Hi,

How about using a structure ??
struct abc
{
  int num;
  int pos;
};
you could create an array of that structure with what so ever
positional values you want, and then sort the array, while doing so
you can swap the whole structure unit instead of a single value.

Or as you have used another array to store the positions, while
sorting, when you swap your value Array, simultaneously you can
change/Interchange the values in the position Array.

--- In [email protected], "anand" <[EMAIL PROTECTED]> wrote:
>
> Hi all,
> i have been trying to write a program that sorts an array for its
> values in increasing order but generates the o/p as the sorted indices
> of those  respective values.
> To make my question clear here is an ex. :
> 
> A[6]={2,6,4,6,2,2};  // array as i/p
> B[6]={2,2,2,4,6,6};  //sorted array
> 
> Now the expected o/p is the indices - A[o],A[4],A[5],A[2],A[1],A[3] !!
> 
> Problem is after sorting the array (which uses swapping) the initial
> indices are lost!
> To avoid this i created a new array(similar to A[] & compared it
> element-wise with sorted array to find a match & then look out for the
> index with a match.But the place where i get stuck is discarding the
> initially found matches!!
> 
> 
> I hope my problem here is clear.
> 
> Kindly suggest me some way to find the solution.
> Also let me know if this approach is OK or if there exists a simpler
> way to reach the required solution.
> 
> Your suggestions/comments would be of great help to me.
> 
> Best regards,
> anand.
>


Reply via email to