import Myro.*; //Pratice with sorting //Friday April 13th, 2012 public class Sorting { final int MAX=100; //create an array and sort it public Sorting() { int[] numbers; //fill the array with random ints //print out the array //sort via selection sort //print out the array //fill the array with random ints //print out the array //sort via bubble sort //print out the array numbers = getRandomArray(MAX); printArray(numbers, MAX); quickSort(numbers, 0, numbers.length - 1); printArray(numbers, MAX); } private int[] getRandomArray(int numElts) { int[] numbers = new int[numElts]; for (int i=0; i= 1) // check that there are at least two elements to sort { int pivot = array[start]; // set the pivot as the first element in the partition while (k > i) // while the scan indices from left and right have not met, { while (array[i] <= pivot && i <= end && k > i) // from the left, look for the first i++; // element greater than the pivot while (array[k] > pivot && k >= start && k >= i) // from the right, look for the first k--; // element not greater than the pivot if (k > i) // if the left seekindex is still smaller than swap(array, i, k); // the right index, swap the corresponding elements } swap(array, start, k); // after the indices have crossed, swap the last element in // the left partition with the pivot quickSort(array, start, k - 1); // quicksort the left partition quickSort(array, k + 1, end); // quicksort the right partition } else // if there is only one element in the partition, do not do any sorting { return; // the array is sorted, so exit } } //selection sort the array, sorting all elts from 0 to array.length-1 public void selectionSort(int array[]) { } //bubble sort the array, sorting all elts from 0 to array.length-1 public void bubbleSort(int array[]) { } }