impliment the selection sort algorithm to sort the elements in a two dimentional array of order 3*4 in descending order. the program should prompt the user to input 12 element, sort and display the elements in the matrix format.
sort each member of first element, and maintain order of second.
And BTW, you have your rows (first element) and columns (second element) reversed! Your 3x4 array should be 3 rows of 4 columns, not the other way around... Think of it as a 2 dimensional array of x and y, where x is the row, and y is the column. You CAN do it the other way around, but it gets messier when you go beyond 2 dimensions and add a z (3rd) dimension... :-)
Getting back to the math - in reality it really doesn't matter, but your matrix[rowindex][colindex] is reversed from what you think it should be. Eyes crossing yet?
i have initializing code in the begining for position in line 8
But in line 25 you need to assign it a value in order for the for loop to work
Also your If statement in 30 shouldn't have a semi-colon.
Your using a keyword to identify a variable, try renaming 'array' to 'myarray'.
'array' is 2d but you're trying to assign a value to temp using the index of only 1 dimension in line 33. In fact you seem to have forgotten about the second dimension all together after line 25.
Also if I'm not mistaken, the reason it's called 'insertion sort' is, that you try to insert each element in it's proper place as it's added to the collection.
By using a 2d array you're complicating it quite a bit. The values in (1,0),(1,1), and (1,2) don't really have any relation to the values in (0,0),(0,1), and (0,2), unless you specify the relationship between them, which adds an extra layer of complexity to your code.
Here's some code that will work. The biggest problem is working with a multidimension array, because by default they're not sequential, but your sort needs to treat them like they are. When you look at the code you might want to make note of a couple of things.
See how using indents makes it much easier to read. I did this on Visual C++ Express, which has a menu option to format the code like this. The same can de done in Code::Blocks, both of which are free.
Using the namespace std, gives you access to the standard librairies for C++ and makes it easier for someone to help you since they don't need your specific set up to run the code. You should specifically stay away from conio.h, that header is not part of a standard set up and in general is no longer used.
You can notice as well, the use of sub routines to compartmentalize the code. This makes debugging much easier.
All that being said, there are probably other opinions on different ways to do this, but this does work, and it is quite simple. Hope all this helps.