fine tune
This commit is contained in:
parent
49fe239cfa
commit
17909162fc
@ -36,9 +36,6 @@ class LinkedListStack {
|
|||||||
/* 出栈 */
|
/* 出栈 */
|
||||||
pop() {
|
pop() {
|
||||||
const num = this.peek();
|
const num = this.peek();
|
||||||
if (!this.#stackPeek) {
|
|
||||||
throw new Error("栈为空!");
|
|
||||||
}
|
|
||||||
this.#stackPeek = this.#stackPeek.next;
|
this.#stackPeek = this.#stackPeek.next;
|
||||||
this.#stkSize--;
|
this.#stkSize--;
|
||||||
return num;
|
return num;
|
||||||
@ -46,9 +43,8 @@ class LinkedListStack {
|
|||||||
|
|
||||||
/* 访问栈顶元素 */
|
/* 访问栈顶元素 */
|
||||||
peek() {
|
peek() {
|
||||||
if (!this.#stackPeek) {
|
if (!this.#stackPeek)
|
||||||
throw new Error("栈为空!");
|
throw new Error("栈为空!");
|
||||||
}
|
|
||||||
return this.#stackPeek.val;
|
return this.#stackPeek.val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,9 +36,8 @@ class LinkedListStack {
|
|||||||
/* 出栈 */
|
/* 出栈 */
|
||||||
pop(): number {
|
pop(): number {
|
||||||
const num = this.peek();
|
const num = this.peek();
|
||||||
if (!this.stackPeek) {
|
if (!this.stackPeek)
|
||||||
throw new Error("栈为空!");
|
throw new Error("栈为空");
|
||||||
}
|
|
||||||
this.stackPeek = this.stackPeek.next;
|
this.stackPeek = this.stackPeek.next;
|
||||||
this.stkSize--;
|
this.stkSize--;
|
||||||
return num;
|
return num;
|
||||||
@ -46,9 +45,8 @@ class LinkedListStack {
|
|||||||
|
|
||||||
/* 访问栈顶元素 */
|
/* 访问栈顶元素 */
|
||||||
peek(): number {
|
peek(): number {
|
||||||
if (!this.stackPeek) {
|
if (!this.stackPeek)
|
||||||
throw new Error("栈为空!");
|
throw new Error("栈为空");
|
||||||
}
|
|
||||||
return this.stackPeek.val;
|
return this.stackPeek.val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user