atanasovetr

SelectionSort

Oct 21st, 2020
855
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. public class SelectionSort {
  2.     public static void main(String[] args) {
  3.         double[] test = {-7,2,4,1,6,2,-9,1};
  4.         sorting(test);
  5.     }
  6.     public static void sorting(double[] unsorted){
  7.  
  8.         for (int i = 0; i < unsorted.length; i++){
  9.             double minimum = unsorted[i];
  10.             double temp;
  11.             for (int j = i+1; j < unsorted.length; j++){
  12.                 if(unsorted[j] < minimum){
  13.                     temp = unsorted[j];
  14.                     unsorted[j] = minimum;
  15.                     unsorted[i] = temp;
  16.                     minimum = temp;
  17.                 }
  18.  
  19.             }
  20.  
  21.         }
  22.         for (int i = 0; i < unsorted.length; i++){
  23.             System.out.println(unsorted[i]);
  24.         }
  25.     }
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment