Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Computer science degree and Foxpro
Message
From
22/07/1999 18:54:42
Mike Yearwood
Toronto, Ontario, Canada
 
 
To
22/07/1999 16:50:23
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00243740
Message ID:
00245062
Views:
21
Yep, the pigeonhole sort <g> (known to any mailroom clerk). It doesn't really require any comparisons. It takes a single pass through the source and stores the values with only one move each. Any other sorting technique compares elements against other elements potentially "moving" all elements more than once.

Its horribly space inefficient as it requires storage for the original list and the sorted. The code is really easy...

Given x element array containing unsorted numbers ranging 1-x (source[x]) and storage array (sorted[x]),

If this code doesn't run, its because I wrote it off the top of my head. You'll get the general idea though.

local x
x = 1000
local array source[x],sorted[x]
local i

*Fill in the source array
for i = 1 to x
source[i] = int(rand(1)*x)+1
endfor

*Now sort the array
for i = 1 to x
sorted[source[i]] = source[i]
endfor

Of course, this is only of interest when the professors didn't know this technique at all.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform