栈
function Stack() {
this.dataStore = []; //底层数据结构是数组
this.top = 0; //top应该是等于数组的length的
this.push = push;
this.pop = pop;
this.peek = peek;
function push(element) {
this.dataStore[this.top++] = element;
}
function pop() {
return this.dataStore[--this.top];
}
function peek() {
return this.dataStore[this.top-1];
}
}
链接:https://blog.csdn.net/haoshidai/article/details/52263191
圣凡无二路,方便有多门。
浙公网安备 33010602011771号