+ 1
How to bubble sort a 2D array?
i am making an assignment for uni.i m trying my best..help
4 odpowiedzi
+ 10
You will need two for loops and one if conditional statement to filter the arrays. E.g. If you want to find the string "cookies" in a 2D array of size 10x10,
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
if (array[i][j] == "cookies")
{
std::cout << "Array has cookies!" << std::endl;
}
}
}
+ 3
I meant are the largest and smallest values in the whole array supposed to be at opposite corners, or are you just sorting within each row (or column)?
I suspect the whole array is to be sorted as a unit, so think about a loop running from 0 to MAXROW*MAXCOL. Could you make that loop access each location in your array?
+ 2
It sounds to me like the problem is not well defined... Do you have any idea how the rows and columns are supposed to be related?
I could see solutions anywhere from just sorting the individual rows to using some div/mod math to make the whole array just slide into the standard algorithm (loops of M*N length, then some math from the indices to sort out right)
0
it may be as arr[rows][col]....