build
This commit is contained in:
parent
ea7cdae9a7
commit
2f5cc98102
@ -804,7 +804,15 @@ comments: true
|
|||||||
=== "Ruby"
|
=== "Ruby"
|
||||||
|
|
||||||
```ruby title="binary_tree_dfs.rb"
|
```ruby title="binary_tree_dfs.rb"
|
||||||
[class]{}-[func]{pre_order}
|
### 前序遍历 ###
|
||||||
|
def pre_order(root)
|
||||||
|
return if root.nil?
|
||||||
|
|
||||||
|
# 访问优先级:根节点 -> 左子树 -> 右子树
|
||||||
|
$res << root.val
|
||||||
|
pre_order(root.left)
|
||||||
|
pre_order(root.right)
|
||||||
|
end
|
||||||
|
|
||||||
### 中序遍历 ###
|
### 中序遍历 ###
|
||||||
def in_order(root)
|
def in_order(root)
|
||||||
|
|||||||
@ -804,7 +804,15 @@ Depth-first search is usually implemented based on recursion:
|
|||||||
=== "Ruby"
|
=== "Ruby"
|
||||||
|
|
||||||
```ruby title="binary_tree_dfs.rb"
|
```ruby title="binary_tree_dfs.rb"
|
||||||
[class]{}-[func]{pre_order}
|
### 前序遍历 ###
|
||||||
|
def pre_order(root)
|
||||||
|
return if root.nil?
|
||||||
|
|
||||||
|
# 访问优先级:根节点 -> 左子树 -> 右子树
|
||||||
|
$res << root.val
|
||||||
|
pre_order(root.left)
|
||||||
|
pre_order(root.right)
|
||||||
|
end
|
||||||
|
|
||||||
### 中序遍历 ###
|
### 中序遍历 ###
|
||||||
def in_order(root)
|
def in_order(root)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user