Java Applets Centre
Selection Sort


Description
This applet demonstrates the working of the Selection Sort algorithm.


Code

public void selectionSort(){
  int i,j,min,temp;
  for(j=0; j < size-1; j++){
   min=j;
   for(i=j+1; i < size; i++)
    if(arr[i] < arr[min]) min=i;
   if(j!=min){
    temp=arr[j];
    arr[j]=arr[min];
    arr[min]=temp;
   }
  }
}


Data Structures and Algorithms
Java Applets Centre


R. Mukundan
Department of Computer Science
University of Canterbury
Private Bag 4800, Christchurch
New Zealand.