Class: SinglyLinkedList
- Inherits:
-
LinkedList
- Object
- LinkedList
- SinglyLinkedList
- Defined in:
- lib/honey_mushroom/singly_linked_list.rb
Instance Attribute Summary
Attributes inherited from LinkedList
Instance Method Summary collapse
Methods inherited from LinkedList
#add, #find, #initialize, #remove_front
Constructor Details
This class inherits a constructor from LinkedList
Instance Method Details
#remove_back ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/honey_mushroom/singly_linked_list.rb', line 5 def remove_back current = @head current = current.next until current.next.next.nil? node = current.next current.next = nil return node end |
#to_s ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/honey_mushroom/singly_linked_list.rb', line 14 def to_s s = '@head->' current = @head until current.nil? s += "[#{current.value}]->" current = current.next end return s end |