Guest User

Node

a guest
Feb 18th, 2013
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. public class Node {
  2.  
  3.     private Node left;
  4.     private Node right;
  5.     private int key;  
  6.     private Object value;
  7.  
  8.     public Node(int key, Object value, Node left, Node right) {
  9.         this.key = key;
  10.         this.value = value;
  11.         this.left = left;
  12.         this.right = right;
  13.     }
  14.  
  15.     public Node(int key, Object value) {
  16.         this.key = key;
  17.         this.value = value;
  18.         // left ja right ovat null
  19.     }
  20.  
  21.     public Node getLeft() {
  22.         return left;
  23.     }
  24.    
  25.     public void setLeft(Node left) {
  26.         this.left = left;
  27.     }
  28.  
  29.     public void setRight(Node right) {
  30.         this.right = right;
  31.     }
  32.  
  33.     public Node getRight() {
  34.         return right;
  35.     }
  36.  
  37.     public Object getValue() {
  38.         return value;
  39.     }
  40.  
  41.     public void setValue(Object value) {
  42.         this.value = value;
  43.     }
  44.  
  45.     public int getKey() {
  46.         return key;
  47.     }
  48.  
  49.     public String toString() {
  50.         String l, r;
  51.        
  52.         if (left == null) {
  53.             l = "null";
  54.         } else {
  55.             l = left.toString();
  56.         }    
  57.         if (right == null) {
  58.             r = "null";
  59.         } else {
  60.             r = right.toString();
  61.         }
  62.         return "Node["+key+","+value+", "+l+", "+r+"]";
  63.     }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment