Given a cryptographically random set of points in 2 dimensional space, connect them all such that they form a polygon without any lines crossing using less than brute force. C/C++ only. Inline assembly accepted as long as it compiles under VS2005 for an x86 chip.

2 winners, The fastest correct solution over a series of runs. and the most elegant (IMO) solution.

the points are in 2 arrays double X[] and double Y[] of size Z

Your function should put them into a second set of arrays NewX[] and NewY[] in the order in which you would draw them if you were playing connect the dots.