Quick actions

cmd+k|ctrl+k

Navigation

Languages

Queues Using Stacks

Snippet info

Language

JavaScript

Visibility

public

Author

jameeulla3

Created

2024-08-21T21:00:51.486883Z

Updated

2024-08-21T21:00:51.486883Z

class Queue{
 constructor(){
     this.front = 0; 
     this.rear = 0; 
     this.length = 0;
     this.stack = [];
     this.revstack = []; 
     
 }   
 enqueue(value)
 {
     this.stack[this.rear]= value; 
     this.rear++; 
}
dequeue(){
    if(this.front>this.rear)
    console.log('empty');
    
    let value = this.stack.splice(this.front,1);
    this.front++;
    return value;
}
 
}
INFO