Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function link(name) {
- this.name = name;
- this.next = null;
- this.prev = null;
- this.setName = function(name) {
- this.name = name;
- }
- this.getName = function() {
- return this.name;
- }
- this.setNext = function(next) {
- this.next = next;
- if(!this.next.prev)
- this.next.prev = this;
- return this;
- }
- this.setPrev = function(prev){
- this.prev = prev;
- if(!this.prev.next)
- this.prev.next = this;
- return this;
- }
- this.getNextName = function() {
- return this.next.getName();
- }
- this.getPrevName = function(){
- return this.prev.getName();
- }
- this.getNext = function() {
- return this.next;
- }
- this.getPrev = function(){
- return this.prev;
- }
- this.hasNext = function() {
- if (this.next == null)
- return false;
- else
- return true;
- }
- this.hasPrev = function(){
- if(this.prev == null)
- return false;
- else
- return true
- }
- this.insert = function insert(after, name){
- ph=this;
- while(ph.name!=after && ph.hasNext()){
- ph=ph.getNext();
- }
- if(ph.hasNext()){
- phnext=ph.getNext();
- }
- ph.setNext(new link(name));
- if(ph.hasNext()){
- ph.getNext().setNext(phnext);
- ph.getNext().getNext().setPrev(ph);
- }
- console.log(ph);
- }
- }
- function load(){
- test = new link("test1");
- test.setNext(new link("wobble").setNext(new link("bobble").setNext(new link("deepest"))));
- addedTop = new link("upper");
- addedTop.setNext(test);
- console.log(addedTop);
- addedTop.insert("bobble","hobble");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement