Update the structure of the chapter

of binary tree.
This commit is contained in:
Yudong Jin
2022-12-21 17:19:39 +08:00
parent f3ef226874
commit f39636cb63
22 changed files with 402 additions and 572 deletions

View File

@ -57,13 +57,6 @@ class ArrayQueue {
return this.queue[this.front];
}
/* 访问指定索引元素 */
get(index: number): number {
if (index >= this.size)
throw new Error("索引越界");
return this.queue[(this.front + index) % this.capacity];
}
/* 返回 Array */
toArray(): number[] {
const siz = this.size;
@ -94,10 +87,6 @@ console.log(queue.toArray());
const peek = queue.peek();
console.log("队首元素 peek = " + peek);
/* 访问指定索引元素 */
const num = queue.get(2);
console.log("队列第 3 个元素为 num = " + num);
/* 元素出队 */
const poll = queue.poll();
console.log("出队元素 poll = " + poll + ",出队后 queue = ");

View File

@ -41,13 +41,6 @@ class ArrayStack {
return this.stack[this.stack.length - 1];
}
/* 访问索引 index 处元素 */
get(index: number): number | undefined {
if (index >= this.size)
throw new Error('索引越界');
return this.stack[index];
}
/* 返回 Array */
toArray() {
return this.stack;
@ -73,10 +66,6 @@ console.log(stack.toArray());
const top = stack.top();
console.log("栈顶元素 top = " + top);
/* 访问索引 index 处元素 */
const num = stack.get(3);
console.log("栈索引 3 处的元素为 num = " + num);
/* 元素出栈 */
const pop = stack.pop();
console.log("出栈元素 pop = " + pop + ",出栈后 stack = ");