--- In [email protected], "Brett McCoy" <[EMAIL PROTECTED]> wrote:
>
> On 10/2/07, anand <[EMAIL PROTECTED]> wrote:
> 
> > i did not write my own sort algorithm.I am using bubble sort method.
> 
> What I meant was whether you were writing the code for the sorting
> (using a standard algorithm) or using a library call like qsort or the
> C++ function sort()? And if not the latter, why not?

HOW sorting is done is not of importance here.Important is i have an
unsorted array,another sorted array & now i need the indices of the 
unsorted array in order/sequence of the values in sorted array.

> 
> > You may look at the foll. code.Here i am showing some random values of
> > i/p & sorted values(assume that sorted values are available as well).
> > This code works fine for shown i/p values but if any value repeats
> > more than twice then the code is not valid anymore!!
> >
> > int ar[5]={24,3,7,45,7};  //unsorted array with nrs. in random order!!
> > int egy[5]={3,7,7,24,45};   //1,2,4,0,3 Xpected output as they are
> > indices of sorted array egy[k]!!!
> 
> I'm not sure why you are hard coding the sorted values here... what's
> the point of sorting if you already know the results? A sort should be
> generic. Are you actually expecting the indices of the array to be in
> the same order as the sort? Where are you even sorting these values?
> 

My array has more than 40 values & my original code is very complex
involving many other operations which might have confused you much
more than this piece has!So i gave this code just as an example.My
original code is taking care of sorting & i did omit that part here to
make it simple.

In the example above,yes i know the expected output but i want to make
it a generalized program for any number of elements in an array.

once again - 1,2,4,0,3 is what i expect as output here for this code
as ar[1]=3 which is smallest,
   ar[2]=7 next higher & so on....... 

> BTW, please spell out words like input and output.  i/p and o/p are
> not standard abbreviations.

will take care of that one!!


> 
> > int k,l,dis=0;
> > bool check;
> >
> > main()
> > {
> >       for(k=0 ; k<5 ; k++)
> >       {
> >               check = false;
> >
> >               for(l=0; l<5  ;l++)
> >               {
> >                 if(egy[k] == ar[l] && l!= dis )      // "&& l!= dis"
> > to avoid previously printed valeus of l ""
> >                       {
> >                              printf("\nIndex = %d",l);
> >                              dis=l;                         //assign
> > dis=l so as to ignore this index in next run!!
> >                              check = true;
> >                        }
> >                        if (check == true)                   //upon a
> > successful match,break the loop!!
> >                        break;
> >               }
> >
> >        }
> >               getchar();
> > }
> >
> >
> >
> >
> > I hope now things are little clear.
> > Thanking you in advance,
> > anand.
> >
> >
> >
> > To unsubscribe, send a blank message to
<mailto:[EMAIL PROTECTED]>.
> > Yahoo! Groups Links
> >
> >
> >
> >
> 
> 
> -- 
> ------------------------------------------------------------
> "In the rhythm of music a secret is hidden;
>     If I were to divulge it, it would overturn the world."
>                -- Jelaleddin Rumi
>


Reply via email to