-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathQueue.js
More file actions
56 lines (52 loc) · 1.05 KB
/
Queue.js
File metadata and controls
56 lines (52 loc) · 1.05 KB
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
46
47
48
49
50
51
52
53
54
55
56
class Queue {
constructor() {
this.dataStore = [];
}
/**
* @name enqueue
* @param {String} elem
* @description
* handler function which will add new element in queue
*/
enqueue(element) {
this.dataStore.push(element);
}
/**
* @name dequeue
* @description
* handler function which will remove element from queue
* @returns {String} RemoveElement
*/
dequeue() {
return this.dataStore.shift();
}
/**
* @name front
* @description
* handler function which provide the first element in queue
* @returns {String} FrontElement
*/
front() {
return this.dataStore[0];
}
/**
* @name back
* @description
* handler function which provide the last element in queue
* @returns {String} BackElement
*/
back() {
return this.dataStore[this.dataStore.length - 1];
}
/**
* @name empty
* @description
* handler function which will clear queue
* @returns {Array} EmptyQueue
*/
empty() {
this.dataStore = [];
return this.dataStore;
}
}
module.exports = Queue;