Thanks for posting this version, I have at least some chance of
reading fortran so I get the general idea of what it is doing.
Funny enough I am working on a test version of a sort algo that
appears to have much the same logic, I am trying to do 2 swaps
for each scan and then swap the lowest in the scan with the
lowest position and the highest in the scan with the highest
position. Inc and Dec the two ends and do it again until all of
the members have been placed.
Edited here !
Here is a a simplified version, its technically a Selection Sort,
a fair bit faster than a bubble sort but a very long way off the
pace to be competitive. It repeatedly scans the array to finds the
shortest member and swaps it with the first member, then increments
the first position. Its swap count is OK but it pays a big penalty
with the number of scans it does.
Code:
'########################################################################## FUNCTION SelSort(ByVal cnt as LONG, _ ' array count ByVal Arr as LONG) as LONG ' array address ' --------------- ' Selection Sort ' --------------- #REGISTER NONE LOCAL lcnt as LONG ! mov esi, Arr ! xor ecx, ecx ! mov lcnt, ecx cSt: ! mov ecx, lcnt ! mov edi, &H6FFFFFFF ; LONG range clbl: ! cmp edi, [esi+ecx*4] ; cmp lowest value holder to current member ! jl cnxt1 ! mov edi, [esi+ecx*4] ; store value in EDI if smaller ! mov edx, ecx ; store the index cnxt1: ! inc ecx ! cmp ecx, cnt ! jne clbl ! mov ebx, lcnt ! mov eax, [esi+edx*4] ; do the swap ! mov ecx, [esi+ebx*4] ! mov [esi+edx*4], ecx ! mov [esi+ebx*4], eax ! inc lcnt ! mov ecx, cnt ! cmp lcnt, ecx ! jne cSt FUNCTION = 0 END FUNCTION '##########################################################################
[email protected]
------------------
[This message has been edited by Steve Hutchesson (edited September 06, 2001).]
Leave a comment: