Thread: Apollo quiz
View Single Post
  #23 (permalink)  
Old 23-November-2004, 11:00 PM
ajv ajv is offline
Member
 
Join Date: Jan 2004
Posts: 60
Default

This simply invokes the C library sorting function, which is implemeted as Quicksort.
I don't believe the C standard requires qsort() to be a Quicksort though.

Also (in Standard C) you should declare qsort() to get full marks:
Code:
#include <stdlib.h>
But, much more seriously, you could get a nasty integer overflow with that subtraction comparison. e.g. with 32 bit
Code:
array[0] = 0;
array[1] = -1500000000;
array[2] = -1500000000;
array[3] = 1500000000;
array[4] = -1500000000;
array[5] = 1500000000;
array[6] = -1500000000;
array[7] = 1500000000;
array[8] = 0;
array[9] = 1500000000;
If the integer exception didn't crash your embedded flight computer, the bad sort order just caused your LM's flight path to intersect the surface.
Reply With Quote