Class: SinglyLinkedList

Inherits:
LinkedList show all
Defined in:
lib/honey_mushroom/singly_linked_list.rb

Instance Attribute Summary

Attributes inherited from LinkedList

#head

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_backObject



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_sObject



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