Selection sort implementation
This commit is contained in:
parent
07cd60e843
commit
01cd19d427
@ -1,31 +1,7 @@
|
||||
package com.baeldung.algorithms.selectionsort;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class SelectionSort {
|
||||
|
||||
/*public static void main(final String args[]) {
|
||||
int[] a = { 5, 4, 1, 6, 2 };
|
||||
|
||||
System.out.println("Unsorted array");
|
||||
System.out.println(IntStream.of(a)
|
||||
.mapToObj(String::valueOf)
|
||||
.collect(Collectors.joining(",")));
|
||||
|
||||
a = sortAscending(a);
|
||||
System.out.println("Ascending Sorted array");
|
||||
System.out.println(IntStream.of(a)
|
||||
.mapToObj(String::valueOf)
|
||||
.collect(Collectors.joining(",")));
|
||||
|
||||
a = sortDescending(a);
|
||||
System.out.println("Descending Sorted array");
|
||||
System.out.println(IntStream.of(a)
|
||||
.mapToObj(String::valueOf)
|
||||
.collect(Collectors.joining(",")));
|
||||
}*/
|
||||
|
||||
public static void sortAscending(final int[] arr) {
|
||||
for (int i = 0; i < arr.length - 1; i++) {
|
||||
int minElementIndex = i;
|
||||
@ -40,11 +16,6 @@ public class SelectionSort {
|
||||
arr[i] = arr[minElementIndex];
|
||||
arr[minElementIndex] = temp;
|
||||
}
|
||||
System.out.println("Iteration No. " + (i + 1));
|
||||
System.out.println(IntStream.of(arr)
|
||||
.mapToObj(String::valueOf)
|
||||
.collect(Collectors.joining(",")));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,11 +33,6 @@ public class SelectionSort {
|
||||
arr[i] = arr[maxElementIndex];
|
||||
arr[maxElementIndex] = temp;
|
||||
}
|
||||
System.out.println("Iteration No. " + (i + 1));
|
||||
System.out.println(IntStream.of(arr)
|
||||
.mapToObj(String::valueOf)
|
||||
.collect(Collectors.joining(",")));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user