PHP Classes
Icontem

File: ListIterator.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Oddleif Halvorsen  >  Double Linked List  >  ListIterator.php  
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
 

Contents

Class file image Download
<?php
/**
 * <p>Title: Double linked list</p>
 * <p>Description: Implementation of a double linked list in PHP</p>
 * @author Oddleif Halvorsen | leif-h@online.no
 * @version 1.2
 */

include_once("Iterator.php"); 

class 
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(){
        if(
$this->hasPrevious()){
            
$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();
        }
        
        return 
FALSE;
    }
}
?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products