This commit is contained in:
krahets
2023-09-13 03:40:35 +08:00
parent 2f051b6ff8
commit 821898534f
6 changed files with 28 additions and 18 deletions

View File

@@ -1660,7 +1660,7 @@ comments: true
}
/* 判断队列是否为空 */
empty() {
isEmpty() {
return this.#queSize === 0;
}
@@ -1689,7 +1689,7 @@ comments: true
/* 访问队首元素 */
peek() {
if (this.empty()) throw new Error('队列为空');
if (this.isEmpty()) throw new Error('队列为空');
return this.#nums[this.#front];
}
@@ -1730,7 +1730,7 @@ comments: true
}
/* 判断队列是否为空 */
empty(): boolean {
isEmpty(): boolean {
return this.queSize === 0;
}
@@ -1759,7 +1759,7 @@ comments: true
/* 访问队首元素 */
peek(): number {
if (this.empty()) throw new Error('队列为空');
if (this.isEmpty()) throw new Error('队列为空');
return this.nums[this.front];
}

View File

@@ -1386,7 +1386,7 @@ comments: true
}
/* 判断栈是否为空 */
empty() {
isEmpty() {
return this.#stack.length === 0;
}
@@ -1397,13 +1397,13 @@ comments: true
/* 出栈 */
pop() {
if (this.empty()) throw new Error('栈为空');
if (this.isEmpty()) throw new Error('栈为空');
return this.#stack.pop();
}
/* 访问栈顶元素 */
top() {
if (this.empty()) throw new Error('栈为空');
if (this.isEmpty()) throw new Error('栈为空');
return this.#stack[this.#stack.length - 1];
}
@@ -1430,7 +1430,7 @@ comments: true
}
/* 判断栈是否为空 */
empty(): boolean {
isEmpty(): boolean {
return this.stack.length === 0;
}
@@ -1441,13 +1441,13 @@ comments: true
/* 出栈 */
pop(): number | undefined {
if (this.empty()) throw new Error('栈为空');
if (this.isEmpty()) throw new Error('栈为空');
return this.stack.pop();
}
/* 访问栈顶元素 */
top(): number | undefined {
if (this.empty()) throw new Error('栈为空');
if (this.isEmpty()) throw new Error('栈为空');
return this.stack[this.stack.length - 1];
}