Skip to content

Instantly share code, notes, and snippets.

@ralbt
ralbt / lru_cache.rb
Last active April 16, 2024 16:52
Ruby: LRU Cache Implementation
class LRUCache
attr_reader :dll, :hash, :count, :capacity
def initialize(capacity)
@dll = DLL.new
@hash = Hash.new
@count = 0
@capacity = capacity
end
def read(key)
@ralbt
ralbt / level_order_traversal.rb
Created May 27, 2017 08:22
Ruby: Level order traversal of binary tree
class BinaryTree
attr_reader :root
def initialize(root)
@root = root
end
def level_order_traversal
if root.nil?
puts "Queue is empty"
@ralbt
ralbt / inorder_tree_traversal.rb
Last active June 24, 2019 09:27
Ruby: Inorder tree traversal with and without recursion
class BinaryTree
attr_reader :root
def initialize(root)
@root = root
end
def print_inorder_with_recursion(current)
return if current.nil?