class DoublyLinkedList
Attributes
tail[RW]
Public Class Methods
new()
click to toggle source
Calls superclass method
LinkedList::new
# File lib/honey_mushroom/doubly_linked_list.rb, line 6 def initialize super @tail = nil end
Public Instance Methods
add(value)
click to toggle source
# File lib/honey_mushroom/doubly_linked_list.rb, line 11 def add(value) node = Node.new({value: value, next: nil, last: nil}) node.next = @head @head = node node.next.last = node unless node.next.nil? @tail = node if @tail.nil? end
remove_back()
click to toggle source
# File lib/honey_mushroom/doubly_linked_list.rb, line 27 def remove_back current = @tail @tail = current.last current.last.next = nil return current end
remove_front()
click to toggle source
# File lib/honey_mushroom/doubly_linked_list.rb, line 19 def remove_front current = @head @head = current.next current.next.last = nil return current end
to_s()
click to toggle source
# File lib/honey_mushroom/doubly_linked_list.rb, line 35 def to_s s = '@head<->' current = @head until current.nil? s += "[#{current.value}]<->" current = current.next end return s end