From 938ced1a12539976a1b2d2118df1a1587b4ea5df Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 15 Jan 2024 21:41:24 +0100 Subject: [PATCH] fix: fix push/unshift Deque MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/deque.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/deque.ts b/src/deque.ts index 25764372..0d55f5b6 100644 --- a/src/deque.ts +++ b/src/deque.ts @@ -38,10 +38,11 @@ export class Deque { * @returns The new size of the queue. */ public push (data: T): number { - const node = { data, prev: this.tail } + const node: ILinkedListNode = { data } if (this.tail == null) { this.head = this.tail = node } else { + node.prev = this.tail this.tail = this.tail.next = node } return this.incrementSize() @@ -54,10 +55,11 @@ export class Deque { * @returns The new size of the queue. */ public unshift (data: T): number { - const node = { data, next: this.head } + const node: ILinkedListNode = { data } if (this.head == null) { this.head = this.tail = node } else { + node.next = this.head this.head = this.head.prev = node } return this.incrementSize() -- 2.34.1