mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-06 22:34:18 +08:00
fix: modify a function name in array_stack.js(ts) and array_queue.js(ts) (#739)
* Update array_stack.js 判空函数名称有歧义 * Update array_stack.js * Update array_queue.js * Update array_stack.ts * Update array_queue.ts --------- Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
@ -17,7 +17,7 @@ class ArrayStack {
|
||||
}
|
||||
|
||||
/* 判断栈是否为空 */
|
||||
empty() {
|
||||
isEmpty() {
|
||||
return this.#stack.length === 0;
|
||||
}
|
||||
|
||||
@ -28,13 +28,13 @@ class ArrayStack {
|
||||
|
||||
/* 出栈 */
|
||||
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];
|
||||
}
|
||||
|
||||
@ -71,5 +71,5 @@ const size = stack.size;
|
||||
console.log('栈的长度 size = ' + size);
|
||||
|
||||
/* 判断是否为空 */
|
||||
const empty = stack.empty();
|
||||
console.log('栈是否为空 = ' + empty);
|
||||
const isEmpty = stack.isEmpty();
|
||||
console.log('栈是否为空 = ' + isEmpty);
|
||||
|
Reference in New Issue
Block a user