/* * æ çå®ç° */ module.exports = function Stack() { // æ ä¸ç屿§ãæ¹æ³ this.dataStore = []; // æ é¡¶è®¡æ° this.top = 0; this.push = push; this.pop = pop; this.peek = peek; this.clear = clear; this.size = size; this.isEmpty = isEmpty; } // 徿 䏿¨å ¥æ°æ® function push(element) { this.dataStore[this.top++] = element; } // 仿 ä¸ååºæ°æ® function pop() { return this.dataStore[--this.top]; } // è·åæ é¡¶çæ°æ® function peek() { return this.dataStore[this.top-1]; } // æ¸ æ¥æ çæ°æ® function clear() { this.top = 0; } // è¿åæ çé¿åº¦ function size() { return this.top; } // 夿æ¯å¦ä¸ºç©º function isEmpty() { return this.top === 0; }