Blogger Information
Blog 19
fans 0
comment 1
visits 18133
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP的队列和栈
王石磊的博客
Original
715 people have browsed it

<?php
 class Stack{
     public static $dataInfo =  array();
     public static $theMax= 10;
     public static $length=0;
    // public static $stackInfo;
     public function addData($data){
         if(self::$length >= self::$theMax){
             return false;
         }else{
           array_push(self::$dataInfo,$data);
           self::$length ++; 
         }
         
     }
     public function outData(){
         if(self::$length<=0 ){
             
             return false;
         }else{
            $data = array_pop(self::$dataInfo);
            self::$length --;
             return $data;
         }
         
         
     }
     
     public function getAll(){
         foreach (self::$dataInfo as $value) {
             // code..
             print_r($value);
         }
     }
     
 }
$a = new Stack();
$a->addData(1);
$a->addData(3);
$a->addData(5);
$a->getAll();
print_r($a->outData());
?>

同理,队列也是一样的 只不过可以把array_pop()换成array_shift()。

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post