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

原文地址:https://www.cnblogs.com/Longhua-0/p/9573152.html