Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

sort rant

Name: Anonymous 2008-04-08 20:55

Seriously... why can't we just do things ONE WAY? All these different types of sorts, for no reason at all except to get a faster running time with programs made for computers that won't even NOTICE the difference between a selection or merge sort. So what if heap sort has a constant O(n log n) time? I don't care! So stop assigning me stupid CS labs telling me to figure out different sorts.
All this from a high school APCS student...

Name: Anonymous 2008-04-12 5:59

void sort(uintmax_t *numbers, size_t length){
 uintmax_t temp[length], *arrays[2] = {numbers, temp};
 for(uint_fast8_t i = 0; i < sizeof(uintmax_t) * CHAR_BIT; ++i){
  for(size_t j = 0, start = 0, end = length - 1; j < length; ++j){
   if(!(arrays[i & 1][j] & 1 << i))
    arrays[i & 1 ^ 1][start++] = arrays[i & 1][j];
   if(arrays[i & 1][length - j - 1] & 1 << i)
    arrays[i & 1 ^ 1][end--] = arrays[i & 1][length - j - 1];
}}}


O(n) time, O(n) space, and the whole thing is only 8 lines of code.

Name: Anonymous 2008-04-12 6:19

>>34
}}}
Holy fuck.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List