public class Node { public Node left; // used for Trees public Node right; // used for Trees public Node up; // used for Trees and Lists public Node next; // used for Lists public Object data; // the actual info stored in the node public float key; // Used to relate this node to other nodes // constructor public Node(Object Data, float Key) { key=Key; data=Data; left=null; right=null; up=null; } public Node(Object Data, Node Up) { data=Data; next=null; up=Up; } public Node RightRelative() { if(up==null) // we're root { // System.out.println("Node : hit root"); if(right==null) { return null; } else { Node temp=right; while(temp.right!=null && temp.left==null) { // System.out.println("Node::RightRelative: going right"); temp=temp.right; } if(temp.right==null) { if(temp!=this) return temp; else return null; } temp=temp.left; while(temp.left!=null) temp=temp.left; return temp; } } if(up.left==this && right==null) // we're a left child { return up; // right rel is our parent } Node temp; if(up.right==this && right==null && left==null) { // System.out.println("Node : going up"); temp=up; while(temp.up!=null && temp.up.right==temp) { // System.out.println("Node::RightRelative: going up"); temp=temp.up; } return temp.up; } // System.out.println("Node : going down"); temp=right; // if(temp==null)System.out.println("temp==null"); while(temp.right!=null && temp.left==null) { temp=temp.right; } if(temp.right==null) { if(temp!=this) return temp; else { return null; } } temp=temp.left; while(temp.left!=null) temp=temp.left; return temp; } // right Relative public Node LeftRelative() { if(up==null) // we're root { if(left == null) return null; else { Node temp=left; while(temp.left!=null && temp.right==null) { temp=left; } if(temp.left==null) { if(temp!=this) return temp; else return null; } temp=temp.right; while(temp.right!=null) temp=temp.right; return temp; } } if(up.left == this && left==null) // we're a left child return null; if(up.right == this && left==null) // we're a left child return up; Node temp=left; while(temp.left!=null && temp.right==null) { temp=left; } if(temp.left==null) { if(temp!=this) return temp; else return null; } temp=temp.right; while(temp.right!=null) temp=temp.right; return temp; } // leftRelative }