Skip to content

Commit 4bb923c

Browse files
author
alxklm
committed
Documentation: adding description for WaveSort
1 parent 3d30f94 commit 4bb923c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/main/java/com/thealgorithms/sorts/WaveSort.java

+15
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@
22

33
/**
44
* The WaveSort algorithm sorts an array so that every alternate element is greater than its adjacent elements.
5+
* This implementation also provides a method to check if an array is wave sorted.
56
*/
67
public class WaveSort implements SortAlgorithm {
8+
/**
9+
* Sorts the given array such that every alternate element is greater than its adjacent elements.
10+
*
11+
* @param array The array to be sorted.
12+
* @param <T> The type of elements in the array, which must be Comparable.
13+
* @return The sorted array.
14+
*/
715
@Override
816
public <T extends Comparable<T>> T[] sort(T[] array) {
917
for (int i = 0; i < array.length; i += 2) {
@@ -17,6 +25,13 @@ public <T extends Comparable<T>> T[] sort(T[] array) {
1725
return array;
1826
}
1927

28+
/**
29+
* Checks if the given array is wave sorted. An array is wave sorted if every alternate element is greater than its adjacent elements.
30+
*
31+
* @param array The array to check.
32+
* @param <T> The type of elements in the array, which must be Comparable.
33+
* @return true if the array is wave sorted, false otherwise.
34+
*/
2035
public <T extends Comparable<T>> boolean isWaveSorted(T[] array) {
2136
for (int i = 0; i < array.length; i += 2) {
2237
if (i > 0 && SortUtils.less(array[i], array[i - 1])) {

0 commit comments

Comments
 (0)