标签:splay 增删改查 堆栈 targe gen cte close size string
栈(stack)又名堆栈,它是一种运算受限的线性表。遵循后进先出原则,像垃圾桶似的。
功能实现依然按照增删改查来进行,内部数据存储可以借用语言原生支持的数组。
function Stack(){ this.data = []; }
数据添加到末尾
push: function (element){ this.data.push(element); }
从末尾删除
pop: function (){ this.data.pop(); }
返回最后一个添加的
peek: function (){ return this.data[this.size() - 1]; }
isEmpty: function (){ return this.data.length == 0; }
clear: function (){ this.data= []; }
size: function (){ return this.data.length; }
print: function (){ console.log(this.data.toString()); }
1 function Stack(){ 2 this.data = []; 3 } 4 Stack.prototype = { 5 push: function (element){ 6 this.data.push(element); 7 }, 8 pop: function (){ 9 this.data.pop(); 10 }, 11 peek: function (){ 12 return this.data[this.data.length - 1]; 13 }, 14 isEmpty: function (){ 15 return this.data.length == 0; 16 }, 17 clear: function (){ 18 this.data= []; 19 }, 20 size: function (){ 21 return this.data.length; 22 }, 23 print: function (){ 24 console.log(this.data.toString()); 25 } 26 }
标签:splay 增删改查 堆栈 targe gen cte close size string
原文地址:http://www.cnblogs.com/donglegend/p/6043330.html