I am programming in C. I have an array of structures. I need to print the array in sorted order based on an element of the structure. The main problem where I am stuck is I do not want to modify the original array.
For example: My array is proctab[10]. This is the array of structure named pentry.
struct pentry
{
int a;
int b;
char c;
}
I need to print as follows:
a = 1, b = 2, c = a
a = 2, b = 1, c = d
a = 3, b = 0, c = e
a = 4, b = 1, c = a
a = 4, b = 2, c = a
and so on.. i.e. the result is sorted on a. but if a has same value for two structures in the array, the array should be sorted on b as well.
I want the original array proctab to remain intact.
Is there any way to do this?