dsa

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

Node.java (762B)


      1 package collections;
      2 
      3 //please note that this code is different from the textbook code, because the data is encapsulated!
      4 
      5 public class Node<T>
      6 {
      7     private T item;
      8     private Node next;
      9 
     10     public Node(T newItem)
     11     {
     12         item = newItem;
     13         next = null;
     14     } // end constructor
     15 
     16     public Node(T newItem, Node nextNode)
     17     {
     18         item = newItem;
     19         next = nextNode;
     20     } // end constructor
     21 
     22     public void setItem(T newItem)
     23     {
     24         item = newItem;
     25     } // end setItem
     26 
     27     public T 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