php 数据结构之"栈"

 1 class Stack
 2 {
 3     private $_data = [];
 4     private $_end = null;
 5 
 6     public function push($data)
 7     {
 8         if($this->_end === null) 
 9             $this->_end = 0;
10         else
11             $this->_end++;
12         $this->_data[$this->_end] = $data;
13     }
14 
15     public function pop()
16     {
17         if(empty($this->_data)) return false;
18 
19         $ret = $this->_data[$this->_end];
20 
21         array_splice($this->_data,$this->_end);
22         $this->_end-- ;
23         return $ret;
24     }
25 
26     public function getData()
27     {
28         return $this->_data;
29     }
30 }


转-- http://www.cnblogs.com/baochuan/archive/2012/06/02/2530386.html

 

posted @ 2017-02-03 16:35  shijiu520  阅读(126)  评论(0)    收藏  举报