Fix bug before commit 5eae708 (#325)
* Fix bug before commit 5eae708 * Update queue.md --------- Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
parent
ea6a43b2b9
commit
62114ce79a
@ -31,8 +31,10 @@ class ArrayQueue {
|
|||||||
|
|
||||||
/* 入队 */
|
/* 入队 */
|
||||||
push(num) {
|
push(num) {
|
||||||
if (this.size == this.capacity)
|
if (this.size == this.capacity) {
|
||||||
throw new Error("队列已满");
|
console.log("队列已满");
|
||||||
|
return;
|
||||||
|
}
|
||||||
// 计算尾指针,指向队尾索引 + 1
|
// 计算尾指针,指向队尾索引 + 1
|
||||||
// 通过取余操作,实现 rear 越过数组尾部后回到头部
|
// 通过取余操作,实现 rear 越过数组尾部后回到头部
|
||||||
const rear = (this.#front + this.size) % this.capacity;
|
const rear = (this.#front + this.size) % this.capacity;
|
||||||
|
@ -11,7 +11,7 @@ class ArrayQueue {
|
|||||||
private queSize: number; // 队列长度
|
private queSize: number; // 队列长度
|
||||||
|
|
||||||
constructor(capacity: number) {
|
constructor(capacity: number) {
|
||||||
this.nums = new Array<number>(capacity);
|
this.nums = new Array(capacity);
|
||||||
this.front = this.queSize = 0;
|
this.front = this.queSize = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,8 +32,10 @@ class ArrayQueue {
|
|||||||
|
|
||||||
/* 入队 */
|
/* 入队 */
|
||||||
push(num: number): void {
|
push(num: number): void {
|
||||||
if (this.size == this.capacity)
|
if (this.size == this.capacity) {
|
||||||
throw new Error("队列已满");
|
console.log("队列已满");
|
||||||
|
return;
|
||||||
|
}
|
||||||
// 计算尾指针,指向队尾索引 + 1
|
// 计算尾指针,指向队尾索引 + 1
|
||||||
// 通过取余操作,实现 rear 越过数组尾部后回到头部
|
// 通过取余操作,实现 rear 越过数组尾部后回到头部
|
||||||
const rear = (this.front + this.queSize) % this.capacity;
|
const rear = (this.front + this.queSize) % this.capacity;
|
||||||
|
@ -1027,8 +1027,10 @@ comments: true
|
|||||||
|
|
||||||
/* 入队 */
|
/* 入队 */
|
||||||
push(num) {
|
push(num) {
|
||||||
if (this.size == this.capacity)
|
if (this.size == this.capacity) {
|
||||||
throw new Error("队列已满");
|
console.log("队列已满");
|
||||||
|
return;
|
||||||
|
}
|
||||||
// 计算尾指针,指向队尾索引 + 1
|
// 计算尾指针,指向队尾索引 + 1
|
||||||
// 通过取余操作,实现 rear 越过数组尾部后回到头部
|
// 通过取余操作,实现 rear 越过数组尾部后回到头部
|
||||||
const rear = (this.#front + this.size) % this.capacity;
|
const rear = (this.#front + this.size) % this.capacity;
|
||||||
@ -1065,7 +1067,7 @@ comments: true
|
|||||||
private queSize: number; // 队列长度
|
private queSize: number; // 队列长度
|
||||||
|
|
||||||
constructor(capacity: number) {
|
constructor(capacity: number) {
|
||||||
this.nums = new Array<number>(capacity);
|
this.nums = new Array(capacity);
|
||||||
this.front = this.queSize = 0;
|
this.front = this.queSize = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1086,8 +1088,10 @@ comments: true
|
|||||||
|
|
||||||
/* 入队 */
|
/* 入队 */
|
||||||
push(num: number): void {
|
push(num: number): void {
|
||||||
if (this.size == this.capacity)
|
if (this.size == this.capacity) {
|
||||||
throw new Error("队列已满");
|
console.log("队列已满");
|
||||||
|
return;
|
||||||
|
}
|
||||||
// 计算尾指针,指向队尾索引 + 1
|
// 计算尾指针,指向队尾索引 + 1
|
||||||
// 通过取余操作,实现 rear 越过数组尾部后回到头部
|
// 通过取余操作,实现 rear 越过数组尾部后回到头部
|
||||||
const rear = (this.front + this.queSize) % this.capacity;
|
const rear = (this.front + this.queSize) % this.capacity;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user