Skip to content

Instantly share code, notes, and snippets.

View wyy1234567's full-sized avatar

wyy1234567

  • New York
View GitHub Profile
@wyy1234567
wyy1234567 / bst.rb
Created May 5, 2020 03:39
this is my implementation of binary search tree in Ruby
class TreeNode
attr_accessor :value, :left, :right
def initialize(value)
@value = value
@left = nil
@right = nil
end
end
@wyy1234567
wyy1234567 / linked_list.rb
Created March 24, 2020 02:13
create LinkedList class
#linked list is composed nodes, each node has a data, than it points to the next node
class LinkedList
#is_empty?: return true if the linked list is empty
def is_empty?
if @head == nil
return true
else
return false
end
@wyy1234567
wyy1234567 / node.rb
Created March 24, 2020 02:11
create Node class. Each node contains a data, and a next pointer which points to the next node
class Node
attr_accessor :data, :next
def initialize(data, next_node = nil)
@data = data
@next = next_node
end
end