// Copyright Jerome Benoit. 2023. All Rights Reserved.
/**
- * Node.
+ * Linked list node.
*
- * @typeParam T - Type of node data.
+ * @typeParam T - Type of linked list node data.
* @internal
*/
-export class Node<T> {
+export class LinkedListNode<T> {
public data: T
- public next?: Node<T>
- public prev?: Node<T>
+ public next?: LinkedListNode<T>
+ public prev?: LinkedListNode<T>
public constructor (data: T) {
this.data = data
* @internal
*/
export class Deque<T> {
- private head?: Node<T>
- private tail?: Node<T>
+ private head?: LinkedListNode<T>
+ private tail?: LinkedListNode<T>
/** The size of the deque. */
public size!: number
/** The maximum size of the deque. */
* @returns The new size of the queue.
*/
public push (data: T): number {
- const node = new Node(data)
+ const node = new LinkedListNode(data)
if (this.tail == null) {
this.head = this.tail = node
} else {
* @returns The new size of the queue.
*/
public unshift (data: T): number {
- const node = new Node(data)
+ const node = new LinkedListNode(data)
if (this.head == null) {
this.head = this.tail = node
} else {
return
}
const tail = this.tail
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.tail = this.tail!.prev
+ this.tail = this.tail?.prev
if (this.tail == null) {
delete this.head
} else {
delete this.head.prev
}
--this.size
- return head?.data
+ return head.data
}
/**
value: node.data,
done: false
}
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- node = node.next!
+ node = node.next
return ret
}
}
value: node.data,
done: false
}
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- node = node.prev!
+ node = node.prev
return ret
}
}