Re: challenge (simplyfying quicksort code)

Liste des GroupesRevenir à cl c  
Sujet : Re: challenge (simplyfying quicksort code)
De : fir (at) *nospam* grunge.pl (fir)
Groupes : comp.lang.c
Date : 27. Mar 2024, 18:30:55
Autres entêtes
Organisation : i2pn2 (i2pn.org)
Message-ID : <uu1hk0$381kj$1@i2pn2.org>
References : 1
User-Agent : Mozilla/5.0 (Windows NT 5.1; rv:27.0) Gecko/20100101 Firefox/27.0 SeaMonkey/2.24
fir wrote:
the chellenge is simplify such quicksort code as far as you can
>
conditions
1) it should work proper way
2) should be not slower or only slightly slower
(so thsi is not optimistation for speed its more for being simple but
staing reasonably fast)
3) by simplify i mean maybe removing soem if or some other
element but not necassary rewriting names for shorter etc as names are
not much meaningfull here  (so by simplifying i mainy understand
removing something or some recomposition for something better/clearer)
4) the basic quicksort has two calls inside this one is
opitmised to have only one , i think both versions are okay
but maybe thsi one with one call inside is maybe better
>
>
void QuicksortInts7(int* table, int lo, int hi)
{
>
     int i=lo; int j=hi;
>
     while (i<hi)
     {
         int pivot =table[(lo+hi)/2];
         while (i<=j)          // Partition
         {
             while (table[i]<pivot) i++;
             while (table[j]>pivot) j--;
             if (i<=j)
             {
                 int t=table[i];table[i]=table[j];table[j]=t;
                 i++; j--;
             }
         }
>
         if (lo < j){ QuicksortInts7(table, lo, j);} //recursion
         lo=i; j=hi;
     }
}
>
>
is there a way to simplify this?
beciuse there is like repetition
 >          while (i<=j)
 >              if (i<=j)
it seems that mayeb thsi could be reduced to one but its to hard for
me ..thsi quicksort transformation is damn hard - some logical knot
(at elast when im not much in form)

Date Sujet#  Auteur
27 Mar 24 * challenge (simplyfying quicksort code)4fir
27 Mar 24 +- Re: challenge (simplyfying quicksort code)1fir
28 Mar 24 `* Re: challenge (simplyfying quicksort code)2Janis Papanagnou
28 Mar 24  `- Re: challenge (simplyfying quicksort code)1fir

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal