/**
* Informatik II - FS2009
* Uebungsserie 2, Aufgabe 1
* SortArray.java
*
* SortArray sorts an array of random generated integer numbers
*
* @author Philipp Bolliger
*/
import java.util.Random;
public class SortArray {
//int-Array with 10 elements
int[] a = new int[10];
//int[] a = {15,3,4,6,7,8,9,10,11,12};
/**
* Initializes an array with uniformly distributed random numbers
*/
void initialize() {
Random r = new Random();
for(int i=0;i a[maxIndex]) {
maxIndex = j;
}
}
// switch maxIndex with i
if (maxIndex != i) {
int tmp = a[i];
a[i] = a[maxIndex];
a[maxIndex] = tmp;
}
// continue sorting the rest of the array
if(i+1
SortArray s = new SortArray();
// Initialise:
s.initialize();
System.out.println("Array unsorted:");
// Output, not sorted:
s.print();
// Sort:
s.sort(0);
System.out.println("Array sorted:");
// Output, sorted:
s.print();
}
}