Sujet : challenge (simplyfying quicksort code) De : fir (at) *nospam* grunge.pl (fir) Groupes :comp.lang.c Date : 27. Mar 2024, 12:04:02 Autres entêtes Organisation : i2pn2 (i2pn.org) Message-ID :<uu0uf4$376ni$1@i2pn2.org> User-Agent : Mozilla/5.0 (Windows NT 5.1; rv:27.0) Gecko/20100101 Firefox/27.0 SeaMonkey/2.24
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?