import java.util.ArrayList; public class TreeSorter { // sorts the ArrayList using BSTreeSort public static void sort(ArrayList list) { //add the data, creating the binary search tree BinarySearchTree bst = new BinarySearchTree(); for( int x : list ) { bst.add(x); } //now do an inorder traversal of the tree, storing //the data from each node back into the array. list.clear(); bst.addToList(list); } //----------- unit test code -------------- public static void main(String[] args) { // build an unsorted list ArrayList list = new ArrayList(); list.add(9); list.add(10); list.add(8); list.add(5); list.add(6); list.add(7); list.add(3); // print the unsorted list for( int x : list) { System.out.print(x + " "); } System.out.println(); // sort the list sort(list); // print the sorted list for( int x : list) { System.out.print(x + " "); } System.out.println(); } }