Skip to content

Commit 0703824

Browse files
committed
feat: add jsDoc comments
1 parent c65d5fb commit 0703824

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

data_structures/linkedlist_queue.ts

+26-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ export class LinkedQueue<T> implements Queue<T> {
3232
this.size = 0;
3333
}
3434

35-
// adds elements to the rear/tail of the Queue
35+
/**
36+
* Adds an item to the queue.
37+
*
38+
* @param item The item being added to the queue.
39+
*/
3640
enqueue(item: T): void {
3741
const node = { value: item } as Node<T>; // Creates a new node
3842
this.size++ // Increase the length of the Queue
@@ -48,10 +52,14 @@ export class LinkedQueue<T> implements Queue<T> {
4852
}
4953

5054

51-
// Remove elements to the front/head of the Queue
55+
/**
56+
* Removes an item from the queue and returns it.
57+
*
58+
* @throws Queue Underflow if the queue is empty.
59+
* @returns The item that was removed from the queue.
60+
*/
5261
dequeue(): T | undefined {
5362

54-
// If there is no head return undefined
5563
if (!this.head) {
5664
throw new Error("Queue Underflow");
5765
}
@@ -63,7 +71,11 @@ export class LinkedQueue<T> implements Queue<T> {
6371
}
6472

6573

66-
// Returns the value of the head
74+
/**
75+
* Returns the item at the front of the queue.
76+
*
77+
* @returns The item at the front of the queue or null if the queue is empty.
78+
*/
6779
peek(): T | undefined | null {
6880

6981
if (this.isEmpty()) {
@@ -72,11 +84,20 @@ export class LinkedQueue<T> implements Queue<T> {
7284
return this.head?.value;
7385
}
7486

75-
// Returns true if the Queue is empty
87+
/**
88+
* Checks if the queue is empty.
89+
*
90+
* @returns {boolean} Whether the queue is empty or not.
91+
*/
7692
isEmpty(): boolean {
7793
return this.size === 0
7894
}
7995

96+
/**
97+
* Returns the number of items in the queue.
98+
*
99+
* @returns {number} The number of items in the queue.
100+
*/
80101
length(): number {
81102
return this.size;
82103
}

0 commit comments

Comments
 (0)