-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path07-dequeue.js
More file actions
40 lines (35 loc) · 839 Bytes
/
Copy path07-dequeue.js
File metadata and controls
40 lines (35 loc) · 839 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
class dequeue{
constructor(){
this.items = []
}
IsEmpty(){
return this.items.length === 0
}
InsertAtEnd(value){
this.items.push(value)
}
DeleteAtFront(){
if(this.IsEmpty()){
console.log('DeQueue is Empty')
}else{
return this.items.shift() // shift remove element from the start
}
}
InsertAtFront(value){
this.items.unshift(value) // add element to the front
}
deleteAtend(){
if(this.IsEmpty()){
console.log('DeQueue is Empty')
}else{
return this.items.pop() // remove element from the end
}
}
}
let dq = new dequeue()
dq.InsertAtFront(10)
dq.InsertAtFront(20)
dq.InsertAtEnd(30)
dq.InsertAtFront(40)
console.log(dq.deleteAtend())
console.log(dq.deleteAtend())