in my problem i have to enter the components of matrix in 2D array
1 5 6
3 9 10
8 23 15
1 3 5
6 8 9
0 15 23
Well there are several methods , but I would go with the simplest...
Assume that you take the dimension of nxn martix as the input from the user where user feeds in value of n. And array is the one in which he feeds in the value.
Just have another integer pointer as
After the user feeds in the value of n you can allocate a linear array as
Use this array to sort your elements out using the pointer itself as index to the array as:
or even as:
Once you are done wit sorting then you can just free the memory as
This would be just like using a temporary array for sorting.
Hope this helps... :)
Casting malloc is a residue practice from the times when the C programming language didn't support void type. It is best not to cast malloc since doing it can hide errors.