免费手机做网站,秦皇岛网络优化招聘,政务网站建设存在的问题,开源saas多用户建站系统栈是只允许在表尾进行插入#xff0c;删除的线性表。特点后进先出。 下面将演示用数组实现的栈 栈初始化#xff1a;创建一个空栈 Init:function(){this.STACKMAX 100;this.stack new Array(this.STACKMACK);this.top -1;return this.stack;
} 判断栈空#xff1a; 若栈为…栈是只允许在表尾进行插入删除的线性表。特点后进先出。 下面将演示用数组实现的栈 栈初始化创建一个空栈 Init:function(){this.STACKMAX 100;this.stack new Array(this.STACKMACK);this.top -1;return this.stack;
} 判断栈空 若栈为空返回true否则返回false Empty:function(){if(this.top-1){return true;}else{return false;}
} 进栈若栈满返回“栈满”。否则将元素elem作为新的栈顶元素。 Push:function(elem){if(this.topthis.STACKMAX-1){return 栈满;}else{this.top;this.stack[this.top] elem;}} 退栈删除栈顶元素并返回其值 Pop:function(){if(this.top-1){return 空栈,无法删除栈顶元素;}else{var x this.stack[this.top];this.top--;return x;}} 读栈顶元素返回栈顶元素 Top:function(){if(this.top!-1){return this.stack[this.top];}else{return 空栈顶元素无返回值;}} 清空栈将栈清空为空栈 Clear:function(){this.top-1;
} 栈长度返回栈的元素个数既栈的长度 Length:function(){return this.top1;
} 栈示例代码如下 var Stack function(){}Stack.prototype{Init:function(){this.STACKMAX 100;this.stack new Array(this.STACKMACK);this.top -1;return this.stack;},Empty:function(){if(this.top-1){return true;}else{return false;}},Push:function(elem){if(this.topthis.STACKMAX-1){return 栈满;}else{this.top;this.stack[this.top] elem;}},Pop:function(){if(this.top-1){return 空栈,无法删除栈顶元素;}else{var x this.stack[this.top];this.top--;return x;}},Top:function(){if(this.top!-1){return this.stack[this.top];}else{return 空栈顶元素无返回值;}},Clear:function(){this.top-1;},Length:function(){return this.top1;}} 在最近的日子里会给出栈的应用的例子在此敬请期待。。。转载于:https://www.cnblogs.com/kuikui/archive/2012/08/08/2627553.html