Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,29 @@
public static void cocktailSort( int[] A ){
boolean swapped;
do {
swapped = false;
for (int i =0; i<= A.length - 2;i++) {
if (A[ i ] > A[ i + 1 ]) {
//test whether the two elements are in the wrong order
int temp = A[i];
A[i] = A[i+1];
A[i+1]=temp;
swapped = true;
}
}
if (!swapped) {
//we can exit the outer loop here if no swaps occurred.
break;
}
swapped = false;
for (int i= A.length - 2;i>=0;i--) {
if (A[ i ] > A[ i + 1 ]) {
int temp = A[i];
A[i] = A[i+1];
A[i+1]=temp;
swapped = true;
}
}
//if no elements have been swapped, then the list is sorted
} while (swapped);
}