Update array stack.

This commit is contained in:
Yudong Jin
2022-12-20 14:13:21 +08:00
parent fe7564d54d
commit fa3eff81d1
9 changed files with 46 additions and 43 deletions

View File

@ -28,16 +28,19 @@ class ArrayStack {
/* 出栈 */
pop() {
if (this.empty()) throw "栈为空";
return this.stack.pop();
}
/* 访问栈顶元素 */
top() {
if (this.empty()) throw "栈为空";
return this.stack[this.stack.length - 1];
}
/* 访问索引 index 处元素 */
get(index) {
if (index >= this.size) throw "索引越界";
return this.stack[index];
}