Advertisement
munsking

wobble bobble

Sep 12th, 2012
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function link(name) {
  2.     this.name = name;
  3.     this.next = null;
  4.     this.prev = null;
  5.  
  6.     this.setName = function(name) {
  7.         this.name = name;
  8.     }
  9.  
  10.     this.getName = function() {
  11.         return this.name;
  12.     }
  13.  
  14.     this.setNext = function(next) {
  15.         this.next = next;
  16.         if(!this.next.prev)
  17.             this.next.prev = this;
  18.         return this;
  19.     }
  20.    
  21.     this.setPrev = function(prev){
  22.         this.prev = prev;
  23.         if(!this.prev.next)
  24.             this.prev.next = this;
  25.         return this;
  26.     }
  27.  
  28.     this.getNextName = function() {
  29.         return this.next.getName();
  30.     }
  31.    
  32.     this.getPrevName = function(){
  33.         return this.prev.getName();
  34.     }
  35.  
  36.     this.getNext = function() {
  37.         return this.next;
  38.     }
  39.    
  40.     this.getPrev = function(){
  41.         return this.prev;
  42.     }
  43.  
  44.     this.hasNext = function() {
  45.         if (this.next == null)
  46.             return false;
  47.         else
  48.             return true;
  49.     }
  50.    
  51.     this.hasPrev = function(){
  52.         if(this.prev == null)
  53.             return false;
  54.         else
  55.             return true
  56.     }
  57.    
  58.     this.insert = function insert(after, name){
  59.         ph=this;
  60.         while(ph.name!=after && ph.hasNext()){
  61.             ph=ph.getNext();
  62.         }
  63.         if(ph.hasNext()){
  64.             phnext=ph.getNext();
  65.         }
  66.         ph.setNext(new link(name));
  67.         if(ph.hasNext()){
  68.             ph.getNext().setNext(phnext);
  69.             ph.getNext().getNext().setPrev(ph);
  70.         }
  71.         console.log(ph);
  72.     }
  73. }
  74.  
  75. function load(){
  76.     test = new link("test1");
  77.     test.setNext(new link("wobble").setNext(new link("bobble").setNext(new link("deepest"))));
  78.     addedTop = new link("upper");
  79.     addedTop.setNext(test);
  80.     console.log(addedTop);
  81.     addedTop.insert("bobble","hobble");
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement