mirror of
https://github.com/krahets/hello-algo.git
synced 2026-08-17 06:00:58 +00:00
feat: Add ruby codes - chapter "Heap" (#1300)
* init heap Ruby * feature: finish chapter heap for ruby * fix delete heap.rb * fix: Fix code style * Update codes/ruby/chapter_heap/my_heap.rb Co-authored-by: khoaxuantu <68913255+khoaxuantu@users.noreply.github.com> * Update codes/ruby/chapter_heap/top_k.rb Co-authored-by: khoaxuantu <68913255+khoaxuantu@users.noreply.github.com> * fix: apply the suggested changes * fix to_a * Update my_heap.rb --------- Co-authored-by: khoaxuantu <68913255+khoaxuantu@users.noreply.github.com> Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
@@ -4,6 +4,8 @@ Created Time: 2024-03-18
|
||||
Author: Xuan Khoa Tu Nguyen (ngxktuzkai2000@gmail.com)
|
||||
=end
|
||||
|
||||
require_relative "./tree_node"
|
||||
|
||||
### 打印矩阵 ###
|
||||
def print_matrix(mat)
|
||||
s = []
|
||||
@@ -68,3 +70,11 @@ end
|
||||
def print_hash_map(hmap)
|
||||
hmap.entries.each { |key, value| puts "#{key} -> #{value}" }
|
||||
end
|
||||
|
||||
### 打印堆 ###
|
||||
def print_heap(heap)
|
||||
puts "堆的数组表示:#{heap}"
|
||||
puts "堆的树状表示:"
|
||||
root = arr_to_tree(heap)
|
||||
print_tree(root)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user