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:
bluebean-cloud
2024-04-28 22:24:51 +08:00
committed by GitHub
parent ca55e818a5
commit a3950e1def
3 changed files with 221 additions and 0 deletions
+10
View File
@@ -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