PHP实现的栈

阅读更多

_end === null){
            $this->_end = 0;
        }else{
            $this->_end++;
        }
        $this->_data[$this->_end] = $data;
    }

    public function pop(){
        if(empty($this->_data)){return false;}
        
        $ret = $this->_data[$this->_end];

        //array_pop($this->_data);
        array_splice($this->_data, $this->_end);

        $this->_end--;
        
        return $ret;
    }

    public function get_data(){
        return $this->_data;
    }

}

$stack = new Stack();
$stack->push('a');
$stack->push('b');
$stack->push('c');
$stack->pop();
print_r($stack->get_data());
 

你可能感兴趣的:(PHP实现的栈)