Hi all,

I just wanted to introduce my little sorting algo that seems pretty fast. (ok ...thats to verify ;))
The algo does the following:

1- determine "a" the smallest value of Tab A.
2- Clear "a" from tab A by moving "-1" to that location (sentinel value)
3- Copy "a" on tab B
4- repeat steps 1, 2, 3 untill tab2 is full.

Hope you'll enjoy.
Posted on 2002-12-02 16:21:32 by Axial
And that's the proc ;)

.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib



Tab db "This is a test-string.",0

TabLen equ $ - OFFSET Tab

Tab2 db TabLen dup (0)


invoke Sort, addr Tab, addr Tab2, TabLen

Sort proc uses edi esi edx ecx src:DWORD, dest:DWORD, len:DWORD

mov edi, dest
mov esi, src
mov edx, edi
mov ecx, esi
add edx, len
add ecx, len

mov ah, byte ptr [esi]
mov al, byte ptr [esi]
cmp al, ah
ja @F
mov ebx, esi
mov ah, al
inc esi
cmp esi, ecx
jnz cont
mov byte ptr [edi], ah
mov byte ptr [ebx], -1 ; sentinel value
mov esi, src
inc edi
cmp edi, edx
jnz Reinit

Sort endp

end start

Posted on 2002-12-02 17:21:21 by Axial
Hi Axial.

Nice job. For very small buffers this is okay. But think for each element in B you are scanning all elements in A, so you are doing length(A)^2 scans. You will find this to be very slow on large buffers.

Take some time and think about how you can optimize. There are many sorting algorithms out there for you to look at. QuickSort, BubbleSort, etc. Compare them to your method.
Posted on 2002-12-02 18:03:01 by iblis
Axial's algorithm actually has a name - Selection Sort.
Posted on 2002-12-04 12:41:20 by tenkey
Check out http://cs.smith.edu/~thiebaut/java/sort/demo.html for a visual display and description of the common sorting algorithms. I am actualy party through writing a heap sort algorithm and hope to have it finished withen the next couple of days, and once I have Ill post it here.
Posted on 2002-12-04 19:31:01 by huh
Another site with some algo demostrations here :alright:
Posted on 2002-12-04 23:51:46 by Miko