Created
January 19, 2019 04:23
-
-
Save imsarvesh/81b80878d4038272f4b33624ae6ae1bc to your computer and use it in GitHub Desktop.
Queue Data Structure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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