home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / admin / stack.inc < prev    next >
Encoding:
Text File  |  2003-03-16  |  1000 b   |  63 lines

  1. <?php
  2. /********************************************************
  3.     include/stack.inc
  4.     
  5.     (C)Copyright 2002 Ryo Chijiiwa <Ryo@IlohaMail.org>
  6.  
  7.     This file is part of IlohaMail, and released under GPL.
  8.     See COPYING, or http://www.fsf.org/copyleft/gpl.html
  9.     
  10.     PURPOSE:
  11.         A simple array based stack class.
  12.  
  13. ********************************************************/
  14.  
  15. class stack{
  16.     var $a;
  17.     var $index;
  18.     
  19.     function stack(){
  20.         $this->a = array();
  21.         $this->index = 0;
  22.     }
  23.     
  24.     function push($val){
  25.         array_unshift($this->a, $val);
  26.     }
  27.  
  28.     function pop(){
  29.         $val = $this->a[0];
  30.         array_shift($this->a);
  31.         return $val;
  32.     }
  33.     
  34.     function top(){
  35.         return $this->a[0];
  36.     }
  37.     
  38.     function reset(){
  39.         $this->index = 0;
  40.     }
  41.     
  42.     function end(){
  43.         return (count($a) - 1);
  44.     }
  45.     
  46.     function next(){
  47.         if ($this->index == count($this->a)) return false;
  48.         else{
  49.             $val = $this->a[$this->index];
  50.             $this->index++;
  51.             return $val;
  52.         }
  53.     }
  54.     
  55.     function clean(){
  56.         $this->a = array();
  57.     }
  58.     
  59.     function dump(){
  60.         return implode(",", $this->a);
  61.     }
  62. }
  63. ?>