Method: DLLModule::DLL#extract_head

Defined in:
lib/food/dll.rb

#extract_headNode

Extract element in DLL head

Returns:

  • (Node)

    value of the node that was in the head



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/food/dll.rb', line 53

def extract_head
  if @head.nil?
    return nil
  else
    @size -= 1
    
    node_to_return = @head
    
    @head = @head.next
    @head.prev = nil
    
    node_to_return.next = nil
    return node_to_return.value
  end
end