So I'm in the middle of a program... part of it requires me to write a funtion to take a 2D array (maximum 20x20) from a file and sort each row. For example:
9 4 2 1 would become 1 2 4 9
3 5 6 2 -------------------2 3 5 6
Also, I need to write another function to sort the columns of a 2D array in descending order.
1 2 3 would become 7 8 9
4 5 6 -------------------4 5 6
7 8 9 -------------------1 2 3
I am having trouble forming the logic to complete these functions. Any help would be much appreciated.
@topic: for the first sort you need 1 for loop, 1variable to save the maximum of each run, 1variable to swap elements of that array.
try to find the maximum of all elements in the first run and swap it to the highest index. in the next run of your for loop your aim is to find the 2nd highest number and swap it to the 2nd highest index. so basically try to find the maximal, save it at the highest index and dont change it again.
for the 2nd sort the idea stays the same, but you need 2 for loops now. 1 to run through the rows and 1 for the colums.
if you can't figure out how to solve it, ask again.