Binary Search Tree (Search)
Description
This applet demonstrates the search operation on a binary search tree.
- Refresh: Every time this button is clicked, the applet creates a new binary search tree. The values at the nodes
are randomly generated.
- Search: Type a value to be searched in the text field, and click the 'Search' button.
Code
(Tree Node)
public class tNode{
int data;
tNode left;
tNode right;
}
|
Code
(BST Search)
boolean
search(int val){
tNode n=root;
while(n.data!=val){
if(val < n.data) n=n.left;
else n=n.right;
if(n==null) return false;
}
return true;
}
|
Data Structures and Algorithms
Java Applets Centre
R. Mukundan
Department of Computer Science
University of Canterbury
Private Bag 4800, Christchurch
New Zealand.