Hey, I'm working on a project that involves sorting a two-dimensional array of integers using bubble sort. I've got it semi-working, my only issue is that it seems to be 'losing' values, I'm assuming when it gets to the end of a line in the array. It also has to run several times to get the values it keeps in completely correct order.
Here's what I've got so far:
Here's what I've got so far:
Code:
int SortArray (int Array[][N], int a, int b)
{
int r, c;
float temp;
for (r = 0; r <= a; r ++)
{
for (c = 0; c <= b; c ++)
{
if (Array[r][c] > Array[r + 1][c] && r + 1 <= a)
{
temp = Array[r][c];
Array[r][c] = Array[r + 1][c];
Array[r + 1][c] = temp;
}
else if (Array[r][c] > Array[r][c + 1] && c + 1 <= b)
{
temp = Array[r][c];
Array[r][c] = Array[r][c + 1];
Array[r][c + 1] = temp;
}
else if (Array[r][c] > Array[r + 1][c + 1] && r + 1 <= a && c + 1 <= b)
{
temp = Array[r][c];
Array[r][c] = Array[r + 1][c + 1];
Array[r + 1][c + 1] = temp;
}
}
}
PrintArray(Array, a, b);
}
Comment