php - 창고

//        

/*$stacklist = array();
array_push($stacklist, "a");
array_push($stacklist, "b");
array_push($stacklist, "c");

$data = array_pop($stacklist);
var_dump($data);*/

/*	  
    	   
*/	                            
class node {

	public $value;   //     
 
	function __construct($value) {
		$this->value = $value;
	}
	
}

/*	 
     
*/	                                                             
class stack{

	public	$last;  //      
	public  $stacklist; //      
	private	$size=0; //      

	//  
	function pop( ){
		if($this->size == 0){
			return null;
			exit('error! the stack is empty!');
		}
		$data = $this->last;
		array_pop($this->stacklist);
		$this->last = end ($this->stacklist);
		$this->size--;
		return $data;
	}

	//  
	function push ($value ){
		$node=new node($value);
		$this->last = $node;
		$this->stacklist[] = $node;
		$this->size++;	
	}
	
	//      ,     
	function end(){
		//         
		
	}
	
	
	function size(){
		return $this->size;
	}

}
//     demo  


$stack = new stack();
for ($j=0;$j<10; $j++){
	$stack ->push($j);
}


while( $node=$stack ->pop() ){
	echo $node->value, "
"; }

좋은 웹페이지 즐겨찾기