算法与数据结构学习
This commit is contained in:
29
Chapter4/stack.mjs
Normal file
29
Chapter4/stack.mjs
Normal file
@ -0,0 +1,29 @@
|
||||
function push(element) {
|
||||
this.dataSource[this.top++] = element;
|
||||
}
|
||||
|
||||
function pop() {
|
||||
return this.dataSource[--this.top];
|
||||
}
|
||||
|
||||
function peek() {
|
||||
return this.dataSource[this.top - 1];
|
||||
}
|
||||
|
||||
function length() {
|
||||
return this.top;
|
||||
}
|
||||
|
||||
function clear() {
|
||||
this.top = 0;
|
||||
}
|
||||
|
||||
export default function Stack() {6
|
||||
this.dataSource = [];
|
||||
this.top = 0;
|
||||
this.push = push;
|
||||
this.pop = pop;
|
||||
this.peek = peek;
|
||||
this.length = length;
|
||||
this.clear = clear;
|
||||
}
|
Reference in New Issue
Block a user