-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue implement.js
51 lines (47 loc) · 899 Bytes
/
queue implement.js
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
class Queue{
constructor(){
this.arr=[];
}
Enqueue(value){
this.arr.push(value);
}
Dequeue(){
if(this.is_empty()){
console.log('under flow');
}
else{
this.arr.shift();
}
}
Front(){
if(this.is_empty()){
console.log('under flow');
}
else return this.arr[0];
}
is_empty(){
let len=this.arr.length-1;
if(len==-1){
return true;
}else return false;
}
display(){
let len=this.arr.length-1;
let ptr=0;
let str='';
while(ptr<=len){
str+=' '+this.arr[ptr];
ptr++;
}
console.log(str);
}
}
// driver code
let qu=new Queue();
qu.Enqueue(10);
qu.Enqueue(20);
qu.Enqueue(30);
qu.Enqueue(40);
qu.Enqueue(50);
qu.Dequeue();
qu.display();