算法与数据结构学习

This commit is contained in:
mol
2024-07-04 22:38:39 +08:00
parent fde7676684
commit 5b61f1d7a1
7 changed files with 610 additions and 0 deletions

29
Chapter4/stack.mjs Normal file
View 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;
}