Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /**
  2.  * This is class Node. *important: data is stored as Object for this exercise
  3.  *
  4.  * @author MUHAMMAD AZRI JASNI
  5.  * @version 10 OCTOBER 2012
  6.  */
  7. public class Node
  8. {
  9.     private Object data;//data carried by this node
  10.     private Node link; // reference to the next node in chain or null if there's none
  11.     /**
  12.      * Constructor for objects of class Node
  13.      */
  14.     //I refer to http:://www.vias.org/javacourse/chap14_02.html
  15.     //and http://www.mycstutorials.com/articles/data_structures/linkedlists
  16.    
  17.     public Node ()//default constructor
  18.     {}
  19.    
  20.     public Node (Object data)
  21.     {
  22.         this.data = data;
  23.         this.link = null;
  24.     }
  25.     public Node (Object data, Node link)//if we want to specify the node to point to.
  26.     {
  27.         this.data = data;
  28.         this.link = link;
  29.     }
  30.     //methods: getData(), getLink(), setData(), setLink()
  31.     public Object getData()
  32.     {  
  33.         return data;
  34.     }
  35.     public void setData(int data)
  36.     {
  37.         this.data = data;
  38.     }
  39.     public Node getLink()
  40.     {
  41.         return link;
  42.     }
  43.     public void setLink(Node link)
  44.     {
  45.         this.link=link;
  46.     }
  47. }