PHP Classes

File: ListIterator.php

Recommend this page to a friend!
  Classes of Oddleif Halvorsen   Double Linked List   ListIterator.php   Download  
File: ListIterator.php
Role: Class source
Content type: text/plain
Description: The list iterator class
Class: Double Linked List
A double linked list similar to LinkedList in Java
Author: By
Last change: v1.2 - Due to the major changes in the internal design of the LinkedList.php the ListIterator.php is aloso updated, and only this version of the ListIterator will work with the current version of LinkedList.php
Date: 18 years ago
Size: 1,465 bytes


Class file image Download
 * <p>Title: Double linked list</p>
 * <p>Description: Implementation of a double linked list in PHP</p>
 * @author Oddleif Halvorsen |
 * @version 1.2


ListIterator extends Iterator{

     * Constructs a ListNode.
     * @param &$head The start of the list
     * @param &$list The LinkedList, nessesary for updating the size of the list on removal of nodes.
function ListIterator(&$head, &$list){
parent::Iterator(&$head, &$list);
     * Checks if more nodes exist
     * @return TRUE == hasNext || FALSE == no next node.
function hasPrevious(){
//it has a previous value if $this->previous != NULL or current node is set an has a previous value set.
return (($this->currentNode != NULL && $this->currentNode->getPrevious() != NULL) || $this->previousNode != NULL ? TRUE : FALSE);
     * Get the reference to the previous node.
     * @param &$node The next node. || FALSE if no next node exists.
function getPrevious(){
$this->currentNode = &$this->currentNode->getPrevious(); //current is the node between previous and next
$this->previousNode = &$this->currentNode->getPrevious(); //previous is the node closer to head
$this->nextNode = &$this->currentNode->getNext(); //next is the node closer to tail

return $this->currentNode->getNodeValue();