HELP sorting arrays
Can anyone please help me change this selection sort into a bubble sort. Any help would be appreciated. Thanks!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
void dualSort(string id[], double rainFall[], int size)
{
int startScan, maxIndex;
string tempid;
double maxValue;
for (startScan = 0; startScan < (size - 1); startScan++)
{
maxIndex = startScan;
maxValue = rainFall[startScan];
tempid = id[startScan];
for (int index = startScan + 1; index < size; index++)
{
if (rainFall[index] > maxValue)
{
maxValue = rainFall[index];
tempid = id[index];
maxIndex = index;
}
}
rainFall[maxIndex] = rainFall[startScan];
id[maxIndex] = id[startScan];
rainFall[startScan] = maxValue;
id[startScan] = tempid;
}
}
|
Do you know the algorithm for bubble sort? It's a bit different than selection sort, and also a lot slower.
I don't want to just give you an implementation.
Bubble sort is, in my opinion, easier to implement.
https://en.wikipedia.org/wiki/Bubble_sort
Thanks for the reply. I figured it out.
Topic archived. No new replies allowed.