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.


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.