@@ -32,7 +32,11 @@ export class LinkedQueue<T> implements Queue<T> {
32
32
this . size = 0 ;
33
33
}
34
34
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
+ */
36
40
enqueue ( item : T ) : void {
37
41
const node = { value : item } as Node < T > ; // Creates a new node
38
42
this . size ++ // Increase the length of the Queue
@@ -48,10 +52,14 @@ export class LinkedQueue<T> implements Queue<T> {
48
52
}
49
53
50
54
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
+ */
52
61
dequeue ( ) : T | undefined {
53
62
54
- // If there is no head return undefined
55
63
if ( ! this . head ) {
56
64
throw new Error ( "Queue Underflow" ) ;
57
65
}
@@ -63,7 +71,11 @@ export class LinkedQueue<T> implements Queue<T> {
63
71
}
64
72
65
73
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
+ */
67
79
peek ( ) : T | undefined | null {
68
80
69
81
if ( this . isEmpty ( ) ) {
@@ -72,11 +84,20 @@ export class LinkedQueue<T> implements Queue<T> {
72
84
return this . head ?. value ;
73
85
}
74
86
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
+ */
76
92
isEmpty ( ) : boolean {
77
93
return this . size === 0
78
94
}
79
95
96
+ /**
97
+ * Returns the number of items in the queue.
98
+ *
99
+ * @returns {number } The number of items in the queue.
100
+ */
80
101
length ( ) : number {
81
102
return this . size ;
82
103
}
0 commit comments