<?php
class stack{
private $top;
private $base;
private $myArr = array();
function __construct(){
$this->top = -1;
$this->base = -1;
}
function push($e){
$this->top++;
$this->myArr[$this->top] = $e;
}
function pop(){
if($this->top == -1){
echo '已经到了栈底!';
}else{
$this->top--;
}
}
function echoStack(){
for($i = 0; $i<=$this->top; $i++){
echo $this->myArr[$i] ;
}
}
}
$myStack = new stack();
$myStack->push(100);
$myStack->push(200);
$myStack->push(300);
$myStack->push(400);
$myStack->echoStack();
$myStack->pop();
$myStack->echoStack();
?>