mirror of
https://github.com/TheAlgorithms/Ruby
synced 2024-12-29 22:24:07 +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)
|
||||
end
|
||||
adjusted_array.drop(1)
|
||||
end
|
||||
end
|
||||
|
||||
#Method to adjust heap in downward manner
|
||||
def adjusted_down(adjusted_array, parent, limit)
|
||||
|
@ -28,7 +28,6 @@ def adjusted_down(adjusted_array, parent, limit)
|
|||
adjusted_array[parent] = top
|
||||
end
|
||||
|
||||
|
||||
#Code for testing heapsort
|
||||
array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15].shuffle
|
||||
print heap_sort(array)
|
|
@ -76,5 +76,4 @@ class SingleList
|
|||
def isEmpty()
|
||||
return (@head==nil)
|
||||
end
|
||||
|
||||
end
|
|
@ -15,9 +15,9 @@ def inorder_traversal(root)
|
|||
if node != nil
|
||||
traverse(node.left, ans)
|
||||
ans.push(node.val)
|
||||
traverse(node.right,ans)
|
||||
traverse(node.right, ans)
|
||||
end
|
||||
end
|
||||
traverse(root,ans)
|
||||
traverse(root, ans)
|
||||
return ans
|
||||
end
|
|
@ -14,10 +14,10 @@ def postorder_traversal(root)
|
|||
def traverse(node, ans)
|
||||
if node != nil
|
||||
traverse(node.left, ans)
|
||||
traverse(node.right,ans)
|
||||
traverse(node.right, ans)
|
||||
ans.push(node.val)
|
||||
end
|
||||
end
|
||||
traverse(root,ans)
|
||||
traverse(root, ans)
|
||||
return ans
|
||||
end
|
|
@ -15,9 +15,9 @@ def preorder_traversal(root)
|
|||
if node != nil
|
||||
ans.push(node.val)
|
||||
traverse(node.left, ans)
|
||||
traverse(node.right,ans)
|
||||
traverse(node.right, ans)
|
||||
end
|
||||
end
|
||||
traverse(root,ans)
|
||||
traverse(root, ans)
|
||||
return ans
|
||||
end
|
|
@ -12,5 +12,3 @@ end
|
|||
puts "GCD(3, 5) = " + euclidean_gcd(3, 5).to_s
|
||||
puts "GCD(3, 6) = " + euclidean_gcd(3, 6).to_s
|
||||
puts "GCD(6, 3) = " + euclidean_gcd(6, 3).to_s
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue