Zurück |
Binary Search Tree animation applet |
|
Binary Search Tree (Insert, Delete)
Description
This applet demonstrates all dictionary operations (including
insert and delete) on a binary search tree. Each of these operations take O(log n) time.
- Insert (Input): Type a value in the text field, and click this button to input that value into the binary
search tree.
- Insert (Random): Click this button to input a randomly generated value into the binary
search tree.
- Delete: Type a value to be deleted in the text field, and click the 'Delete' button.
- 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
Quelle: http://www.cosc.canterbury.ac.nz/mukundan/dsal/BTree.html
R. Mukundan
Department of Computer Science
University of Canterbury
Private Bag 4800, Christchurch
New Zealand.