mirror of
https://github.com/TheAlgorithms/Ruby
synced 2025-01-02 06:20:50 +01:00
Merge pull request #47 from Doppon/fix-ruby-syntax
Fix syntax of ruby code, and Unify the naming convention with snake case
This commit is contained in:
commit
26a7610238
13 changed files with 101 additions and 105 deletions
|
@ -14,7 +14,7 @@ def heap_sort(array)
|
||||||
adjusted_down(adjusted_array, 1, array_size)
|
adjusted_down(adjusted_array, 1, array_size)
|
||||||
end
|
end
|
||||||
adjusted_array.drop(1)
|
adjusted_array.drop(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
#Method to adjust heap in downward manner
|
#Method to adjust heap in downward manner
|
||||||
def adjusted_down(adjusted_array, parent, limit)
|
def adjusted_down(adjusted_array, parent, limit)
|
||||||
|
@ -28,7 +28,6 @@ def adjusted_down(adjusted_array, parent, limit)
|
||||||
adjusted_array[parent] = top
|
adjusted_array[parent] = top
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
#Code for testing heapsort
|
#Code for testing heapsort
|
||||||
array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15].shuffle
|
array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15].shuffle
|
||||||
print heap_sort(array)
|
print heap_sort(array)
|
|
@ -76,5 +76,4 @@ class SingleList
|
||||||
def isEmpty()
|
def isEmpty()
|
||||||
return (@head==nil)
|
return (@head==nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
|
@ -15,9 +15,9 @@ def inorder_traversal(root)
|
||||||
if node != nil
|
if node != nil
|
||||||
traverse(node.left, ans)
|
traverse(node.left, ans)
|
||||||
ans.push(node.val)
|
ans.push(node.val)
|
||||||
traverse(node.right,ans)
|
traverse(node.right, ans)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
traverse(root,ans)
|
traverse(root, ans)
|
||||||
return ans
|
return ans
|
||||||
end
|
end
|
|
@ -14,10 +14,10 @@ def postorder_traversal(root)
|
||||||
def traverse(node, ans)
|
def traverse(node, ans)
|
||||||
if node != nil
|
if node != nil
|
||||||
traverse(node.left, ans)
|
traverse(node.left, ans)
|
||||||
traverse(node.right,ans)
|
traverse(node.right, ans)
|
||||||
ans.push(node.val)
|
ans.push(node.val)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
traverse(root,ans)
|
traverse(root, ans)
|
||||||
return ans
|
return ans
|
||||||
end
|
end
|
|
@ -15,9 +15,9 @@ def preorder_traversal(root)
|
||||||
if node != nil
|
if node != nil
|
||||||
ans.push(node.val)
|
ans.push(node.val)
|
||||||
traverse(node.left, ans)
|
traverse(node.left, ans)
|
||||||
traverse(node.right,ans)
|
traverse(node.right, ans)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
traverse(root,ans)
|
traverse(root, ans)
|
||||||
return ans
|
return ans
|
||||||
end
|
end
|
|
@ -12,5 +12,3 @@ end
|
||||||
puts "GCD(3, 5) = " + euclidean_gcd(3, 5).to_s
|
puts "GCD(3, 5) = " + euclidean_gcd(3, 5).to_s
|
||||||
puts "GCD(3, 6) = " + euclidean_gcd(3, 6).to_s
|
puts "GCD(3, 6) = " + euclidean_gcd(3, 6).to_s
|
||||||
puts "GCD(6, 3) = " + euclidean_gcd(6, 3).to_s
|
puts "GCD(6, 3) = " + euclidean_gcd(6, 3).to_s
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue