Implementation

Class: LinkedListIterator.

Constants

Attributes

node

A LinkedList Node instance.

position

The Integer list location. The position is at least 0 and less than the list's size less one.

Methods

initialize(l_n = nil)

def initialize(l_n = nil)
self.node = l_n
self.position = ZERO
end

Initializes a LinkedListIterator instance. Takes a Node argument. Sets node the argument, and sets position zero. Returns the initialized instance.

element()

def element()
return node()
end

Gets position's list element. The element reference.

position()

def position()
return @position
end

Gets position. Returns the Integer.

data()

def data()
node = node()
data = node.d()
return data
end

Gets node's data. Returns the DataType type instance.

data=(dti = nil)

def data=(dti = nil)
node().substitute(dti)
return dti
end

Sets node's data. Takes a DataType type instance argument, dti. The argument replaces node's data. Returns the argument.

===(inst = nil)

def ===(inst = nil)
return equal?(inst)
end

Identity comparison operator. Compares the argument and self. Takes any instance argument, inst. Returns true in the case the iterators are identical. Returns false otherwise.

==(inst = nil)

def ==(inst = nil)
nodes_uneq = false
case
when !inst.instance_of?(LinkedListIterator)
return nodes_uneq
when !(position().eql?(inst.position()) && node().eql?(inst.node_ref()))
return nodes_uneq
else
nodes_uneq = !nodes_uneq
end
return nodes_uneq
end

Attribute equality operator. Compares the argument and self. Takes any argument instance, inst. Returns true in the case the argument is a LinkedListIterator instance, and, the iterators are attributively equal. Attribute equality refers the attributes are 'eql?'.

prev()

def prev()
error = IndexError
unless (node().back_attached())
raise(error, 'The position is zero.')
else
n_a = node().adapt()
self.node = n_a.back()
self.position -= ONE
end
return nil
end

Decrements the list position. Sets node node's back reference. Decrements position. Returns nil.

next()

def next()
error = IndexError
unless (node().front_attached())
raise(error, 'The position is the list\'s size less one.')
else
n_a = node().adapt()
self.node = n_a.front()
self.position += ONE
end
return nil
end

Increments the list position. Sets node node's front reference. Increments position. Returns nil.

node_ref() protected

def node_ref()
return node()
end

Gets node's reference. Returns the reference.