dsa

Data Structures & Algorithms - Spring 2018
Log | Files | Refs | README

DNode.java (1017B)


      1 package lab4;
      2 
      3 //please note that this code is different from the textbook code, because the data is encapsulated!
      4 
      5 public class DNode
      6 {
      7     private Object item;
      8     private DNode next;
      9     private DNode back;
     10 
     11     public DNode(Object newItem)
     12     {
     13         item = newItem;
     14         next = this;
     15         back = this;
     16     } // end constructor
     17 
     18     public DNode(Object newItem, DNode nextNode, DNode previousNode)
     19     {
     20         item = newItem;
     21         next = nextNode;
     22         back = previousNode;
     23     } // end constructor
     24 
     25     public void setItem(Object newItem)
     26     {
     27         item = newItem;
     28     } // end setItem
     29 
     30     public Object getItem()
     31     {
     32         return item;
     33     } // end getItem
     34 
     35     public void setNext(DNode nextNode)
     36     {
     37         next = nextNode;
     38     } // end setNext
     39 
     40     public DNode getNext()
     41     {
     42         return next;
     43     } // end getNext
     44 
     45     public void setBack(DNode previousNode) {
     46         back = previousNode;
     47     }
     48 
     49     public DNode getBack() {
     50         return back;
     51     }
     52 } // end class Node