Sunday, February 24, 2013
Test Selection Sort
public class Testselectionsort {
public static void main(String[] args) {
int list[]={2, 56, 34, 25, 73, 46, 89, 10, 5, 16};
int i;
selectionSort(list, 10);
System.out.println("After sorting, the list elements are:");
for(i=0; i<10; i++)
System.out.print(list[i]+" ");
System.out.println();
}
public static void selectionSort(int[] list, int listLength){
int index;
int smallestIndex;
int minIndex;
int temp;
for(index=0; index<listLength-1; index++){
smallestIndex = index;
for(minIndex = index+1; minIndex<listLength;minIndex++);
temp = list[smallestIndex];
list[smallestIndex]=list[index];
list[index]=temp;
}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment