MCPcopy Create free account
hub / github.com/TheAlgorithms/Java / sort

Method sort

src/main/java/com/thealgorithms/sorts/SwapSort.java:12–27  ·  view source on GitHub ↗
(T[] array)

Source from the content-addressed store, hash-verified

10public class SwapSort implements SortAlgorithm {
11
12 @Override
13 public <T extends Comparable<T>> T[] sort(T[] array) {
14 int index = 0;
15
16 while (index < array.length - 1) {
17 final int amountSmallerElements = this.getSmallerElementCount(array, index);
18
19 if (amountSmallerElements > 0) {
20 SortUtils.swap(array, index, index + amountSmallerElements);
21 } else {
22 index++;
23 }
24 }
25
26 return array;
27 }
28
29 private <T extends Comparable<T>> int getSmallerElementCount(final T[] array, final int index) {
30 int counter = 0;

Callers

nothing calls this directly

Calls 2

swapMethod · 0.95

Tested by

no test coverage detected