public class Node {
	int iData;
	double dData;
	Node leftChild;
	Node rightChild;
	public void displayNode(){
public class Tree {
	private Node root; //the root of the tree
	public Node find(int key) // find node with given key
	{ // (assumes non-empty tree)
	Node current = root; // start at root
	while(current.iData != key) // while no match,
	if(key < current.iData) // go left?
	current = current.leftChild;
	current = current.rightChild; // or go right?
	if(current == null) // if no child,
	return null; // didn't find it
	return current; // found it
	public void insert(int id, double dd){
		Node newNode = new Node(); // make new node
		newNode.iData = id; // insert data
		newNode.dData = dd;
		if(root==null) // no node in root
		root = newNode;
		else // root occupied
		Node current = root; // start at root
		Node parent;
		while(true) // (exits internally)
		parent = current;
		if(id < current.iData) // go left?
		current = current.leftChild;
		if(current == null) // if end of the line,
		{ // insert on left
		parent.leftChild = newNode;
		} // end if go left
		else // or go right?
		current = current.rightChild;
		if(current == null) // if end of the line
		{ // insert on right
		parent.rightChild = newNode;
		} // end else go right
		} // end while
		} // end else not root
		} // end insert()
	public void delete(int id){}
	//various other methods
	public void inOrder(){ //utility function
	private void inOrderRead(Node localRoot){
		while(localRoot != null){
public class TreeApp {
	public static void main(String[]args){
		Tree theTree = new Tree();
		theTree.insert(50, 1.5);
		theTree.insert(41, 50.0);
		theTree.insert(11, 0.0);

Edited 6 Years Ago by javanew: n/a

??? I don't know why ceyesuma is talking about XML here. ???

javanew, when you say your code "doesn't work", what do you mean? Are you getting an error when you compile? When you run? Is it not doing what you expect? If that's the case, please describe the program's behavior and how that differs from what you expect.

it just gives an EROOR >>it doesn't run >>null pointer exception ?? why ??

It also indicates which line that is occurring on. Look at that line and note which variables you are making method calls on. One of them is null and you need to figure out why it doesn't have a value.

It shows null pointer excepetion on the driver class ...
line 7 >>theTree.insert(41, 50.0);

but i dont know why ?? can anybody help me please ?? its very urgent

This article has been dead for over six months. Start a new discussion instead.