I'm sure everyone has seen this at one time or another. I'm having trouble with the selection sort class.
It should take this input:
apple
Apple
Zone
apple
And return it as:
1:a:Apple
0:a:apple
3:a:apple
2:z:Zone
I'm getting it as #0,1,3,2.
here is the snippet I'm working with. Thanks for any help.
static class SelectionSort {
static int[] sortValues(String[][] dataArray, int wordCount) {
int y;
int z;
int temp;
int minIndex;
String[] tempArray;
// Array that holds the sorted element's indexes
// initialize the indexes array
int[] sortedIndexArray = new int[wordCount];
for (y = 0; y < wordCount; y++) {
sortedIndexArray[y] = y;
}
//sort
for (z = y - 1; z < wordCount; z++) {
minIndex = z;
for (y = z - 1; y < wordCount; y++) {
if (dataArray[y][0].compareTo(dataArray[minIndex][0]) < 0) {
minIndex = y;
}
}
if (minIndex != z) {
temp = sortedIndexArray[z];
sortedIndexArray[z] = sortedIndexArray[minIndex];
sortedIndexArray[minIndex] = temp;
tempArray = dataArray[z];
dataArray[z] = dataArray[minIndex];
dataArray[minIndex] = tempArray;
}
}
return sortedIndexArray;
}
}