import java.util.Random; import java.awt.*; public class SortTime { private static Graph myGraph; private static Object[] original; private static Object[] originalSorted; private Object[] sorted; private static int MAX; public SortTime (int xscale,int yscale, String graphTitle) { //create the graph object with the specified x-axis, y-axis, and title myGraph=new Graph(xscale, yscale, graphTitle); MAX=2*xscale; Random rand=new Random(); //create an array of CDs that have random titles for sorting original=new CD[MAX]; originalSorted=new CD[MAX]; for (int y=0;ymyGraph.getX()*2) stop=myGraph.getX()*2; //start over with an unsorted array, but the number of items to sort will increase for (int i=start; i myGraph.getX()) myGraph.setX(i + i/10); if (time > myGraph.getY()) myGraph.setY(time + time/20); //show the updated graph myGraph.repaint(); } } public static void main(String[] args) { //set up the graph with the x-range, y-range, and title SortTime timer=new SortTime(10000,2000,"Sorting Times"); //run simulations for various sorting techinques //starting number to sort, ending number to sort, step size for simulation, title of set of points, color of set of points, sorting algorithm to use (see above) timer.go(1,1900,100,"Selection",Color.blue,1); timer.go(1,1900,100,"Insertion",Color.red,2); timer.go(1,1900,100,"Bubble",Color.yellow,3); timer.go(1,5000,100,"Merge",Color.green,4); timer.go(1,10000,100,"Quick",Color.white,5); timer.go(1,10000,100,"Radix",Color.gray,6); } }