Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
1
Task/Visualize-a-tree/Ruby/visualize-a-tree-1.rb
Normal file
1
Task/Visualize-a-tree/Ruby/visualize-a-tree-1.rb
Normal file
|
|
@ -0,0 +1 @@
|
|||
root = BinaryTreeNode.from_array [1, [2, [4, 7], [5]], [3, [6, [8], [9]]]]
|
||||
2
Task/Visualize-a-tree/Ruby/visualize-a-tree-2.rb
Normal file
2
Task/Visualize-a-tree/Ruby/visualize-a-tree-2.rb
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
require 'pp'
|
||||
pp root
|
||||
12
Task/Visualize-a-tree/Ruby/visualize-a-tree-3.rb
Normal file
12
Task/Visualize-a-tree/Ruby/visualize-a-tree-3.rb
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
def ptree(tree,indent=" ")
|
||||
case tree
|
||||
when Array
|
||||
head,*tail=tree
|
||||
ptree(head,indent)
|
||||
s=tail.size-1
|
||||
tail.each_with_index { |tree1,i| ptree(tree1,"#{indent}#{((i==s) ? ' ':'|')} ") }
|
||||
else
|
||||
puts(indent.gsub(/\s\s$/,"--").gsub(/ --$/,"\\--")+tree.to_s)
|
||||
end
|
||||
end
|
||||
ptree [1,2,3,[4,5,6,[7,8,9]],3,[22,33]]
|
||||
Loading…
Add table
Add a link
Reference in a new issue