Skip to content

Instantly share code, notes, and snippets.

@imsarvesh
Created January 19, 2019 04:23
Show Gist options
  • Save imsarvesh/81b80878d4038272f4b33624ae6ae1bc to your computer and use it in GitHub Desktop.
Save imsarvesh/81b80878d4038272f4b33624ae6ae1bc to your computer and use it in GitHub Desktop.
Queue Data Structure
//Queue Data Structure
function createQueue(){
const q = [];
return {
//enque
enque(item){
return q.push(item);
},
//deque
deque(item){
return q.shift();
},
//peek
peek(){
return q[0];
},
//length
get length(){
return q.length;
},
//isEmpty
isEmpty(){
return q.length === 0
}
}
}
const queue = createQueue()
queue.enque('First');
queue.enque('Second');
queue.enque('Third');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment