dsa

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

Node.java (777B)


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