Code changes by request
This commit is contained in:
parent
186c5d0253
commit
952accaf48
@ -1,4 +1,3 @@
|
|||||||
package Sorts;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -18,10 +17,12 @@ class CocktailShakerSort {
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
public static <T extends Comparable<T>> void CS(T array[], int last) {
|
public static <T extends Comparable<T>> void CS(T array[], int last) {
|
||||||
|
|
||||||
// Sorting
|
// Sorting
|
||||||
boolean swap;
|
boolean swap;
|
||||||
do {
|
do {
|
||||||
swap = false;
|
swap = false;
|
||||||
|
|
||||||
//front
|
//front
|
||||||
for (int count = 0; count <= last - 2; count++) {
|
for (int count = 0; count <= last - 2; count++) {
|
||||||
int comp = array[count].compareTo(array[count + 1]);
|
int comp = array[count].compareTo(array[count + 1]);
|
||||||
@ -32,10 +33,12 @@ class CocktailShakerSort {
|
|||||||
swap = true;
|
swap = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!swap) { //break if no swap occurred
|
//break if no swap occurred
|
||||||
|
if (!swap) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
swap = false;
|
swap = false;
|
||||||
|
|
||||||
//back
|
//back
|
||||||
for (int count = last - 2; count >= 0; count--) {
|
for (int count = last - 2; count >= 0; count--) {
|
||||||
int comp = array[count].compareTo(array[count + 1]);
|
int comp = array[count].compareTo(array[count + 1]);
|
||||||
@ -47,7 +50,8 @@ class CocktailShakerSort {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
last--;
|
last--;
|
||||||
} while (swap); //end
|
//end
|
||||||
|
} while (swap);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Driver Program
|
// Driver Program
|
||||||
|
Loading…
Reference in New Issue
Block a user