> it apparently takes a sorting routine to test sorting routines
You don't have to sort to check sortedness.
boolean isSorted(int[] original, int[] sorted) {
if (original.length != sorted.length)
return false;
for (int i = 0; i < original.length; i++) {
if (i > 0 && sorted[i] < sorted[i - 1])
return false;
if (countInstances(original[i], original) != countIntasnces(original[i], sorted))
return false;
}
return true;
}
int countInstances(int value, int[] array) {
int count = 0;
for (int v : array) {
if (v == value)
count++;
}
return count;
}
I know that bubble sort, selection sort, and insertion sort can be implemented in about half the code as this. But this code is read-only and is more obviously correct than trying to prove an algorithm that mutates the array.
It occurs to me that the "you're helping" might read as snark and it wasn't really intended that way, or at least, not as snark at you, but rather all of us.
It's silly to reject help from e.g. peer review, static analysis, smarter / safer languages. If you look at some tool and say "What kind of idiot would make the mistakes this catches?" the answer is almost certainly "idiots like you".
You don't have to sort to check sortedness.
I know that bubble sort, selection sort, and insertion sort can be implemented in about half the code as this. But this code is read-only and is more obviously correct than trying to prove an algorithm that mutates the array.