Version: 1.0
Type: Class
Category: Other
License: GNU General Public License
Description: Simple Stack class, implemented push, pop and simple stack display functions.
// Stack class
// 19-oct-2000
// Andrej Kvasnica, JPD development Ltd.
// andrej@jpd.sk
// v1.0
class Stack
{
var $vals;
var $amount;
var $maximum;
//constructor
function Stack() {
$this->amount=0;
$this->maximum=0;
}
function push($number){
if ($this->maximum > $this->amount){
$this->vals[$this->amount]=$number;
} else {
$this->vals[]=$number;
$this->maximum++;
};
$this->amount++;
return $this->amount;
}
function pop(){
if ($this->amount){
$this->amount--;
return $this->vals[$this->amount];
} else {
die("stack empty");
};
}
function display($before,$after,$ending){
for ($i=0; $i < $this->amount; $i++) {
echo $before.$this->vals[$i].$after;
};
echo $ending;
}
function size(){
return $this->amount;
}
function maxsize(){
return $this->maximum;
}
};