Skip to content

Commit 952acca

Browse files
author
MattBizzo
committed
Code changes by request
1 parent 186c5d0 commit 952acca

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Sorts/CocktailShakerSort.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
package Sorts;
21

32
/**
43
*
@@ -18,10 +17,12 @@ class CocktailShakerSort {
1817
**/
1918

2019
public static <T extends Comparable<T>> void CS(T array[], int last) {
20+
2121
// Sorting
2222
boolean swap;
2323
do {
2424
swap = false;
25+
2526
//front
2627
for (int count = 0; count <= last - 2; count++) {
2728
int comp = array[count].compareTo(array[count + 1]);
@@ -32,10 +33,12 @@ public static <T extends Comparable<T>> void CS(T array[], int last) {
3233
swap = true;
3334
}
3435
}
35-
if (!swap) { //break if no swap occurred
36+
//break if no swap occurred
37+
if (!swap) {
3638
break;
3739
}
3840
swap = false;
41+
3942
//back
4043
for (int count = last - 2; count >= 0; count--) {
4144
int comp = array[count].compareTo(array[count + 1]);
@@ -47,7 +50,8 @@ public static <T extends Comparable<T>> void CS(T array[], int last) {
4750
}
4851
}
4952
last--;
50-
} while (swap); //end
53+
//end
54+
} while (swap);
5155
}
5256

5357
// Driver Program

0 commit comments

Comments
 (0)