- this.decrementSize()
- return this.nodeArray.shift()?.data
- }
-
- /**
- * Peeks at the first data.
- * @returns The first data or `undefined` if the priority queue is empty.
- */
- public peekFirst (): T | undefined {
- return this.nodeArray[0]?.data
- }
-
- /**
- * Peeks at the last data.
- * @returns The last data or `undefined` if the priority queue is empty.
- */
- public peekLast (): T | undefined {
- return this.nodeArray[this.nodeArray.length - 1]?.data
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ const data = tail!.dequeue()
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ if (tail!.empty()) {
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ if (!tailChanged && tail!.next != null) {
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ this.tail = tail!.next
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ delete tail!.next
+ } else if (tailChanged) {
+ let node: PriorityQueueNode<T> | undefined = this.tail
+ while (node != null) {
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ if (node.next === tail && tail!.next != null) {
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ node.next = tail!.next
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ delete tail!.next
+ break
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ } else if (node.next === tail && tail!.next == null) {
+ delete node.next
+ this.head = node
+ break
+ }
+ node = node.next
+ }
+ }
+ }
+ return data