build a bst as an array using recursion?
Posted
by Jack B
on Stack Overflow
See other posts from Stack Overflow
or by Jack B
Published on 2010-04-29T08:43:39Z
Indexed on
2010/04/29
8:47 UTC
Read the original article
Hit count: 413
recursion
String[] dictionary = new String[dictSize]; //arrray of strings from dictionary
String[] tree = new String[3*dictSize]; //array of tree
void makeBST() {
recMakeBST(0, dictionary.length-1);
}//makeBST()
int a=0; void recMakeBST(int low, int high) { if(high-low==0){ return; } else{ int mid=(high-low)/2; tree[a]=dictionary[mid];
a=a+1;
recMakeBST(low, mid-1);
a=a+1;
recMakeBST(mid+1, high); } }
© Stack Overflow or respective owner