This commit is contained in:
mindfulminun committed 2023-02-01 22:20:55 -06:00
1 parent db4a8529f7
commit 8d0e185e96
8 files changed
+269 -5

No files matched your search

+2
View File
@@ -28,6 +28,7 @@ export class Stack<T> implements Iterable<T> {
return el
}
/** Preview the topmost element of the stack without removing it. */
peek(): T | undefined {
if (this.length === 0) return undefined
return this.#elements[this.#head - 1]
@@ -73,6 +74,7 @@ export class Queue<T> implements Iterable<T> {
return el
}
/** Preview the next element in the queue without removing it. */
peek(): T | undefined {
if (this.length === 0) return undefined
return this.#elements[this.#head]