I was scouring my old homeworks for something I need and found this - probably might help somebody. :grin:
[size=9]siftDown PROC USES ebx lpArray:DWORD, root:DWORD, bottom:DWORD


mov ebx, lpArray

__subAlgoA:

mov eax, root
shl eax, 1

cmp eax, bottom
ja __subAlgoC
jne __nextA

mov edx, eax
jmp __subAlgoB

__nextA:

mov ecx, DWORD PTR [ebx+eax*4]
cmp ecx, DWORD PTR [ebx+eax*4+4]

jbe __nextB

mov edx, eax
jmp __subAlgoB

__nextB:

lea edx, [eax+1]

__subAlgoB:

mov eax, root

mov ecx, DWORD PTR [ebx+eax*4]
cmp ecx, DWORD PTR [ebx+edx*4]

jae __subAlgoC

push ecx
mov ecx, DWORD PTR [ebx+edx*4]
mov DWORD PTR [ebx+eax*4], ecx
pop DWORD PTR [ebx+edx*4]
mov root, edx
jmp __subAlgoA

__subAlgoC:

ret

siftDown ENDP

HeapSort PROC USES ebx esi lpArray:DWORD, arrLen:DWORD

mov esi, lpArray
mov ebx, arrLen
shr ebx, 1

__mainAlgoA:

test ebx, ebx
js __mainAlgoB

invoke siftDown, esi, ebx, arrLen

dec ebx
jmp __mainAlgoA

__mainAlgoB:

mov ebx, arrLen

__mainAlgoC:

cmp ebx, 1
jb __finish

mov eax, DWORD PTR [esi]
mov ecx, DWORD PTR [esi+ebx*4]
mov DWORD PTR [esi], ecx
mov DWORD PTR [esi+ebx*4], eax

dec ebx

invoke siftDown, esi, 0, ebx

jmp __mainAlgoC

__finish:

ret

HeapSort ENDP[/size]
Posted on 2003-05-05 03:28:15 by arkane
here's some minor changes...

I remember a bug I encountered a year ago but I'm not sure if this is the algo I'm talking about. It happens on a specific sequence of numbers.

I can't remember if it was the quick sort, insertion sort(linked list), or this one.

Posted on 2003-05-05 13:20:01 by arkane