/*
* 对象堆栈
* author: 吴安国
* version: 1.0
*/
function Stack() {
this.stack = new Array();
}
/**
* 移除堆栈顶部的对象,并作为此函数的值返回该对象。
* @return object
*/
Stack.prototype.pop = function(){
return this.stack.shift();
};
/**
* 把项压入堆栈顶部。
* @param object
*/
Stack.prototype.push = function(object) {
this.stack.unshift(object);
};
/**
* 查看堆栈顶部的对象,但不从堆栈中移除它。
* @return object
*/
Stack.prototype.peek = function() {
return this.stack[0];
};
/**
* 测试堆栈是否为空, 空返回true
* @return true or false
*/
Stack.prototype.empty= function() {
return this.stack.length == 0;
};