Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SelectionSort {
- public static void main(String[] args) {
- double[] test = {-7,2,4,1,6,2,-9,1};
- sorting(test);
- }
- public static void sorting(double[] unsorted){
- for (int i = 0; i < unsorted.length; i++){
- double minimum = unsorted[i];
- double temp;
- for (int j = i+1; j < unsorted.length; j++){
- if(unsorted[j] < minimum){
- temp = unsorted[j];
- unsorted[j] = minimum;
- unsorted[i] = temp;
- minimum = temp;
- }
- }
- }
- for (int i = 0; i < unsorted.length; i++){
- System.out.println(unsorted[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment