fine tune

This commit is contained in:
Yudong Jin 2022-12-24 12:53:16 +08:00
parent 49fe239cfa
commit 17909162fc
2 changed files with 7 additions and 13 deletions

View File

@ -36,9 +36,6 @@ class LinkedListStack {
/* 出栈 */
pop() {
const num = this.peek();
if (!this.#stackPeek) {
throw new Error("栈为空!");
}
this.#stackPeek = this.#stackPeek.next;
this.#stkSize--;
return num;
@ -46,9 +43,8 @@ class LinkedListStack {
/* 访问栈顶元素 */
peek() {
if (!this.#stackPeek) {
if (!this.#stackPeek)
throw new Error("栈为空!");
}
return this.#stackPeek.val;
}

View File

@ -36,9 +36,8 @@ class LinkedListStack {
/* 出栈 */
pop(): number {
const num = this.peek();
if (!this.stackPeek) {
throw new Error("栈为空!");
}
if (!this.stackPeek)
throw new Error("栈为空");
this.stackPeek = this.stackPeek.next;
this.stkSize--;
return num;
@ -46,9 +45,8 @@ class LinkedListStack {
/* 访问栈顶元素 */
peek(): number {
if (!this.stackPeek) {
throw new Error("栈为空!");
}
if (!this.stackPeek)
throw new Error("栈为空");
return this.stackPeek.val;
}