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?
> 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?
BTW, please spell out words like input and output. i/p and o/p are
not standard abbreviations.
> 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