garavindbabu
asked on
Getting original indices of strings after sorting a char*name
hi all,
const char* name[max];
i have some strings in name like some names.
i use some sort technique to sort strings in name.after sorting if i need to know the original position of the strings before sorting, how can i do it.
eg:
name= abc,dba,mba,ccb;
sorted name = abc,ccb,dba,mba;
previously mba was at position 3 bur after sorting at 4. so how to get the original positions of the strings.
Thanks and regards
aravind
const char* name[max];
i have some strings in name like some names.
i use some sort technique to sort strings in name.after sorting if i need to know the original position of the strings before sorting, how can i do it.
eg:
name= abc,dba,mba,ccb;
sorted name = abc,ccb,dba,mba;
previously mba was at position 3 bur after sorting at 4. so how to get the original positions of the strings.
Thanks and regards
aravind
ASKER
hi sunny,
can u be more specific.i understand u r concept ,but i could not implement it.can u write some sample code for it.
Thanks for help.
aravind
can u be more specific.i understand u r concept ,but i could not implement it.can u write some sample code for it.
Thanks for help.
aravind
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
> after sorting if i need to know the original position of the strings before
> sorting, how can i do it
there is no way to do it after you have sorted unless you keep a copy of the original data structure or an index of the form (previus position - string name) ... clearly keeping a copy of the original data structure is more efficient ...
alternatively, you can define a struct like
struct a
{
char * name;
int old_pos;
};
and use an array of this struct
struct a b[max];
while you are sorting, save the original indices
Cheers!
Sunny:o)