/Structure_Linked_List.php

Description

Linked list structure

This package implements a doubly linked list structure. Each node (Structure_Linked_List_Node object) in the list (Structure_Linked_List) knows the previous node and the next node in the list. Unlike an array, you can insert or delete nodes at arbitrary points in the list.

Structure_Linked_List implements the Iterator interface so control structures like foreach($list as $node) and while($list->next()) work as expected.

To use this package, derive a child class from Structure_Linked_List_Node and add data to the object. Then use the Structure_Linked_List class to access the nodes.

  1.  <?php
  2.  
  3.  require 'Structure_Linked_List.php';
  4.  
  5.  class Tester extends Structure_Linked_List_Link {
  6.      protected $_my_number;
  7.  
  8.      function __construct($tester$num{
  9.          $this->_my_number $num;
  10.          parent::__construct($tester);
  11.      }
  12.  
  13.      function getNumb({
  14.          return $this->_my_number;
  15.      }
  16.  
  17.      function setNumb($numb{
  18.          $this->_my_number $numb;
  19.      }
  20.  }
  21.  $tester new Tester(null1);
  22.  $xyy new Structure_Linked_List($tester);
  23.  $tester2 new Tester($tester2);
  24.  $tester3 new Tester($tester23);
  25.  $tester4 new Tester($tester4);
  26.  
  27.  $link $xyy->current();
  28.  print $link->getNumb();
  29.  print "\n";
  30.  
  31.  // iterate through the list with while()
  32.   while ($link $xyy->next()) {
  33.      print $link->getNumb();
  34.  }
  35.  
  36.  // rewind the list pointer to the root node
  37.   $link $xyy->rewind();
  38.  
  39.  // test foreach() iteration
  40.   foreach ($xyy as $bull{
  41.    print $bull->getNumb();
  42.  }
  43.  ?>

PHP version 5

LICENSE: This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Classes
Class Description
Structure_Linked_List The Structure_Linked_List class represents a linked list structure composed of Structure_Linked_List_Node objects.
Structure_Linked_List_Node The Structure_Linked_List_Node class represents a node in a Structure_Linked_List linked list structure.
Includes
require_once ('PEAR/ErrorStack.php') (line 93)
Constants
STRUCTURE_LINKED_LIST_ADD_AFTER = 2 (line 109)

Add link after the target link in the linked list

STRUCTURE_LINKED_LIST_ADD_APPEND = 0 (line 99)

Add link to the end of the linked list

STRUCTURE_LINKED_LIST_ADD_BEFORE = 1 (line 104)

Add link before the target link in the linked list

Variables
array $GLOBALS["_Structure_Linked_List_messages"] (line 124)

Error messages

ErrorStack $GLOBALS["_Structure_Linked_List_stack"] (line 118)

Error message stack

Documentation generated on Thu, 24 Aug 2006 10:43:31 -0400 by phpDocumentor 1.3.0