<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">/*
 *  Selection sort
 */
public class SortNum {
  
  /* Sort the values in array a in non-descending order using the 
   * SELECTION SORT algorithm
   */
  public static void selectSort(double[] a){
    int min_loc;  // index of min in unsorted segment
    double temp;
    
    // loop from first to second last element
    // i is the start of the unsorted segment
    for (int i=0; i&lt;a.length-1; i++){
      
      // find index of min in unsorted segment
      min_loc= i;
      // compare each element j in unsorted segment with min found so far
      for (int j=i+1; j&lt;a.length; j++)
        if (a[j]&lt;a[min_loc])
           min_loc= j;
      
      // swap ith element with min
      temp= a[min_loc];
      a[min_loc]= a[i];
      a[i]= temp;
    }
  } //method selectSort
  
  
  /* Test the selectSort method */
  public static void main(String[] args) {
    double[] arr= new double [] {2,6,3,4,5,5,6,3,1,9};
    
    System.out.println("Before sorting:");
    for (int i=0; i&lt;arr.length; i++)  
      System.out.print(arr[i] + " ");
    System.out.println();
    
    selectSort(arr);
    System.out.println("After sorting:");
    for (int i=0; i&lt;arr.length; i++)  
      System.out.print(arr[i] + " ");
    System.out.println();
  } //main
  
} //class SortNum

</pre></body></html>