optimize sort
Author |
Message |
the_binary_soul
|
Posted: Tue Feb 15, 2005 10:24 am Post subject: optimize sort |
|
|
Hello. I'm working on a gr 12. review for a compsci class, and I can't for the life of me how to optimize this sort.
this is the code I have so far.
code: | const LENGTH : int := 10 %%Number of number
var NUM : array 1 .. LENGTH of int
var NUMTEMP : int %% temp variable
var KEY : string (1)
var NUMCHECK : int := 0
put "unsorted Array"
for r : 1 .. LENGTH
NUM (r) := Rand.Int (1, 100)
put NUM (r), " " ..
end for
put " "
for i : 1 .. LENGTH
for j : 1 .. LENGTH - 1
NUMCHECK += 1
if NUM (i) < NUM (j) then
NUMTEMP := NUM (i)
NUM (i) := NUM (j)
NUM (j) := NUMTEMP
end if
end for
end for
put "sorted array"
for r : 1 .. LENGTH
put NUM (r), " " ..
end for
put "checked", NUMCHECK |
It is simply to sort the array lowest to highest and needs to be optimized |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Delos
|
Posted: Tue Feb 15, 2005 10:42 am Post subject: (No subject) |
|
|
Right now you have the wonderfully simple Bubble sort implemented. This is a sinch to programme, but boy is it slow and inefficient.
Search for "sort" in Turing Source Code, and you should find a thread by zylum that shows a lot of really good (and some not so good) sorts.
Basically, you can't optimize that particular sort very much more. It's about as good as it gets. You need a new sort.
This place has a lot of ideas that you can use to make a better sort. Just look around and read the descriptions. |
|
|
|
|
|
the_binary_soul
|
Posted: Tue Feb 15, 2005 10:43 am Post subject: (No subject) |
|
|
thanks |
|
|
|
|
|
|
|