mirror of
https://github.com/TheAlgorithms/Ruby
synced 2024-12-26 21:58:56 +01:00
fix syntax of data_structures
This commit is contained in:
parent
04fd348291
commit
9c1823739c
5 changed files with 54 additions and 55 deletions
|
@ -76,5 +76,4 @@ class SingleList
|
|||
def isEmpty()
|
||||
return (@head==nil)
|
||||
end
|
||||
|
||||
end
|
|
@ -1,23 +1,23 @@
|
|||
# Definition for a binary tree node.
|
||||
# class TreeNode
|
||||
# attr_accessor :val, :left, :right
|
||||
# def initialize(val)
|
||||
# @val = val
|
||||
# @left, @right = nil, nil
|
||||
# end
|
||||
# attr_accessor :val, :left, :right
|
||||
# def initialize(val)
|
||||
# @val = val
|
||||
# @left, @right = nil, nil
|
||||
# end
|
||||
# end
|
||||
|
||||
# @param {TreeNode} root
|
||||
# @return {Integer[]}
|
||||
def inorder_traversal(root)
|
||||
ans = []
|
||||
def traverse(node, ans)
|
||||
if node != nil
|
||||
traverse(node.left, ans)
|
||||
ans.push(node.val)
|
||||
traverse(node.right,ans)
|
||||
end
|
||||
ans = []
|
||||
def traverse(node, ans)
|
||||
if node != nil
|
||||
traverse(node.left, ans)
|
||||
ans.push(node.val)
|
||||
traverse(node.right, ans)
|
||||
end
|
||||
traverse(root,ans)
|
||||
return ans
|
||||
end
|
||||
traverse(root, ans)
|
||||
return ans
|
||||
end
|
|
@ -1,20 +1,20 @@
|
|||
# Definition for a binary tree node.
|
||||
# class TreeNode
|
||||
# attr_accessor :val, :left, :right
|
||||
# def initialize(val)
|
||||
# @val = val
|
||||
# @left, @right = nil, nil
|
||||
# end
|
||||
# attr_accessor :val, :left, :right
|
||||
# def initialize(val)
|
||||
# @val = val
|
||||
# @left, @right = nil, nil
|
||||
# end
|
||||
# end
|
||||
|
||||
# @param {TreeNode} root
|
||||
# @return {TreeNode}
|
||||
def invert_tree(root)
|
||||
if root == nil
|
||||
return nil
|
||||
end
|
||||
temp = root.left
|
||||
root.left = invert_tree(root.right)
|
||||
root.right = invert_tree(temp)
|
||||
return root
|
||||
if root == nil
|
||||
return nil
|
||||
end
|
||||
temp = root.left
|
||||
root.left = invert_tree(root.right)
|
||||
root.right = invert_tree(temp)
|
||||
return root
|
||||
end
|
|
@ -1,23 +1,23 @@
|
|||
# Definition for a binary tree node.
|
||||
# class TreeNode
|
||||
# attr_accessor :val, :left, :right
|
||||
# def initialize(val)
|
||||
# @val = val
|
||||
# @left, @right = nil, nil
|
||||
# end
|
||||
# attr_accessor :val, :left, :right
|
||||
# def initialize(val)
|
||||
# @val = val
|
||||
# @left, @right = nil, nil
|
||||
# end
|
||||
# end
|
||||
|
||||
# @param {TreeNode} root
|
||||
# @return {Integer[]}
|
||||
def postorder_traversal(root)
|
||||
ans = []
|
||||
def traverse(node, ans)
|
||||
if node != nil
|
||||
traverse(node.left, ans)
|
||||
traverse(node.right,ans)
|
||||
ans.push(node.val)
|
||||
end
|
||||
ans = []
|
||||
def traverse(node, ans)
|
||||
if node != nil
|
||||
traverse(node.left, ans)
|
||||
traverse(node.right, ans)
|
||||
ans.push(node.val)
|
||||
end
|
||||
traverse(root,ans)
|
||||
return ans
|
||||
end
|
||||
traverse(root, ans)
|
||||
return ans
|
||||
end
|
|
@ -1,23 +1,23 @@
|
|||
# Definition for a binary tree node.
|
||||
# class TreeNode
|
||||
# attr_accessor :val, :left, :right
|
||||
# def initialize(val)
|
||||
# @val = val
|
||||
# @left, @right = nil, nil
|
||||
# end
|
||||
# attr_accessor :val, :left, :right
|
||||
# def initialize(val)
|
||||
# @val = val
|
||||
# @left, @right = nil, nil
|
||||
# end
|
||||
# end
|
||||
|
||||
# @param {TreeNode} root
|
||||
# @return {Integer[]}
|
||||
def preorder_traversal(root)
|
||||
ans = []
|
||||
def traverse(node, ans)
|
||||
if node != nil
|
||||
ans.push(node.val)
|
||||
traverse(node.left, ans)
|
||||
traverse(node.right,ans)
|
||||
end
|
||||
ans = []
|
||||
def traverse(node, ans)
|
||||
if node != nil
|
||||
ans.push(node.val)
|
||||
traverse(node.left, ans)
|
||||
traverse(node.right, ans)
|
||||
end
|
||||
traverse(root,ans)
|
||||
return ans
|
||||
end
|
||||
traverse(root, ans)
|
||||
return ans
|
||||
end
|
Loading…
Reference in a new issue