-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
45 lines (39 loc) · 921 Bytes
/
Copy pathindex.ts
File metadata and controls
45 lines (39 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* Queue data structure that follows the First In First Out (FIFO) principle.
*/
class Queue<T> {
private items: T[]
constructor() {
this.items = []
}
/**
* Adds an item to the queue.
* @param {T} item - The item to add to the back of the queue.
* @returns {void}
*/
enqueue(item: T): void {
this.items.push(item)
}
/**
* Removes an item from the queue.
* @returns {T | undefined} - The item at the front of the queue.
*/
dequeue(): T | undefined {
return this.items.shift()
}
/**
* Returns the item at the front of the queue without removing it.
* @returns {T} - The item at the front of the queue.
*/
get front(): T {
return this.items[0]
}
/**
* Returns the number of items in the queue.
* @returns {number} - The number of items in the queue.
*/
get size(): number {
return this.items.length
}
}
export default Queue