Class: DoubleLinkedList::Sequence

Inherits:
Object
  • Object
show all
Defined in:
lib/double_linked_list/sequence.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(head:, last:) ⇒ Sequence

Returns a new instance of Sequence.



4
5
6
7
# File 'lib/double_linked_list/sequence.rb', line 4

def initialize(head:, last:)
  @head = head
  @last = last
end

Instance Attribute Details

#headObject (readonly)

Returns the value of attribute head.



3
4
5
# File 'lib/double_linked_list/sequence.rb', line 3

def head
  @head
end

#lastObject (readonly)

Returns the value of attribute last.



3
4
5
# File 'lib/double_linked_list/sequence.rb', line 3

def last
  @last
end

Instance Method Details

#nextObject



9
10
11
12
# File 'lib/double_linked_list/sequence.rb', line 9

def next
  return unless next?
  last.next
end

#next?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/double_linked_list/sequence.rb', line 14

def next?
  last.next ? true : false
end