Advertisement
rizky_herucakra

simple FIFO Queue javascript

May 30th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Queue(){
  2.      var head = null;
  3.      var curr = null;
  4.      
  5.      this.empty = function(){ if (head === null) return true; else return false;}
  6.      this.push  = function(val){
  7.                       if (head === null){
  8.                 head = { value : val, next : null };
  9.                 curr = head;
  10.                } else {
  11.                 curr.next = { value : val, next : null };
  12.                 var tmp = curr.next;
  13.                 curr = tmp;
  14.                }
  15.              }
  16.  
  17.      this.top = function(){
  18.                     if (head === null ) return null;
  19.             else return head.value;
  20.                      }
  21.  
  22.          this.pop = function(){
  23.                     if(head !== null){
  24.                   head = head.next;
  25.             } else {
  26.                   curr = null;
  27.             }
  28.                    }     
  29.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement