* 压栈(进栈、入栈)操作。
*
* @param mixed $data 压栈数据。
* @return object 返回对象本身。
*/
public function push($data) {
$this->stack[$this->size++] = $data;
return $this;
}
/**
* 弹栈(退栈、出栈)操作。
*
* @return mixed 空栈时返回 FALSE,否则返回栈顶元素。
*/
public function pop() {
if (!$this->isEmpty()) {
$top = array_splice($this->stack, --$this->size, 1);
return $top[0];
}
return FALSE;
}
/**
* 获取栈。
*
* @return array 返回栈。
*/
public function getStack() {
return $this->stack;
}
/**
* 获取栈顶元素。
*
* @return mixed 空栈时返回 FALSE,否则返回栈顶元素。
*/
public function getTop() {
if (!$this->isEmpty()) {
return $this->stack[$this->size - 1];
}