X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fdeque.ts;h=52441a3ec25f4f7251575104a0884f9ffeb22d00;hb=b358c8aca5934f7d5dc4bd234d1909ba13850ea9;hp=027aa70dd94def236319bffaa565235d00244045;hpb=b1577cd97272354f930ee506a09a4d930903c68c;p=poolifier.git diff --git a/src/deque.ts b/src/deque.ts index 027aa70d..52441a3e 100644 --- a/src/deque.ts +++ b/src/deque.ts @@ -1,4 +1,4 @@ -// Copyright Jerome Benoit. 2023. All Rights Reserved. +// Copyright Jerome Benoit. 2023-2024. All Rights Reserved. /** * Linked list node interface. @@ -35,13 +35,14 @@ export class Deque { * Appends data to the deque. * * @param data - Data to append. - * @returns The new size of the queue. + * @returns The new size of the deque. */ 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() @@ -51,13 +52,14 @@ export class Deque { * Prepends data to the deque. * * @param data - Data to prepend. - * @returns The new size of the queue. + * @returns The new size of the deque. */ 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()