Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Queue(){
- var items = [];
- var p = "";
- this.enqueue = function(element){
- items.push(element);
- }
- this.dequeue = function(){
- items.shift();
- }
- this.front = function(){
- if(items.length === 0){
- return 'Null Array';
- }else{
- return items[0];
- }
- }
- this.isEmpty = function(){
- if(items.length === 0){
- return false;
- }else{
- return true;
- }
- }
- this.size = function(){
- return items.length;
- }
- this.print = function(){
- for (var i = 0;i < items.length;i++){
- p += items[i];
- }
- return p;
- }
- }
- var q = new Queue();
- q.enqueue(1);
- q.enqueue(2);
- q.enqueue(3);
- console.log(q.print());
- q.dequeue();
- console.log(q.print());
Add Comment
Please, Sign In to add comment