Urgent : Binary Search Tree problem

Thread Solved

Join Date: Nov 2008
Posts: 6
Reputation: soniagupta98 is an unknown quantity at this point 
Solved Threads: 0
soniagupta98 soniagupta98 is offline Offline
Newbie Poster

Urgent : Binary Search Tree problem

 
-2
  #1
Dec 16th, 2008
interface BinarySearchTree {
public void insert(Integer data);
public int size();
public int height();
public boolean contains(Integer target);
}

and I have to implement BST with all these functions. I have implemented the first insert and size like this way -

class Node {
Node left, right, next;
Integer data;
Node () {
left = right = null;
data = 0;
}
}

public class BSTree extends Node implements BinarySearchTree {
static Node root;
static int countNode;
/**
* Creates a new instance of BSTree
*/
public BSTree() {
root = null;
}
public void insert(Integer data) {
if (root == null) {
root.data = data;
countNode++;
} else {
Node temp = new Node();
temp = root;
while (temp != null) {
if (temp.data < data) temp = temp.right;
else {
temp = temp.left;
}
temp.data = data;
countNode++;
}
}
}
public int size () {
return countNode;
}

public int height() {}
public boolean contains (Integer target) {}

public static void main(String[] args) {

BSTree bs = new BSTree();
bs.insert(12);
bs.insert(3);
bs.insert(14);
}

}

Can any one help me by writing the code of finding the height and contains function ?
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 128
Reputation: PhiberOptik is an unknown quantity at this point 
Solved Threads: 4
PhiberOptik's Avatar
PhiberOptik PhiberOptik is offline Offline
Junior Poster

Re: Urgent : Binary Search Tree problem

 
0
  #2
Dec 16th, 2008
Please post your code in tags, its almost impossible to read without them.
Last edited by PhiberOptik; Dec 16th, 2008 at 2:15 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1,175
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 125
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: Urgent : Binary Search Tree problem

 
0
  #3
Dec 16th, 2008
Originally Posted by PhiberOptik View Post
Please post your code in tags, its almost impossible to read without them.
Already had given her this advice in the first clone of this thread, but she just rather chose to just ignore it and created this one
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

"How to ask questions the smart way ?"
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 128
Reputation: PhiberOptik is an unknown quantity at this point 
Solved Threads: 4
PhiberOptik's Avatar
PhiberOptik PhiberOptik is offline Offline
Junior Poster

Re: Urgent : Binary Search Tree problem

 
0
  #4
Dec 17th, 2008
Originally Posted by stephen84s View Post
Already had given her this advice in the first clone of this thread, but she just rather chose to just ignore it and created this one
Oh wow. I don't see very much mod activity on this forum...maybe some more mods, or just more intense actions.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC