News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

i need use the quicksort function nrQsortA do you have some example

Started by jlopezs104, June 07, 2012, 07:07:16 AM

Previous topic - Next topic

jlopezs104

hi i´m in a trouble with a homework about the quicksort function in masm32 if you have a some example i will thank you a lot. i saw a threads with examples here but i can't see that.

BogdanOntanu

There is a "no homework" requests rule in those forums...

Show us what you did and we might help you do your own work.

Please do not ask us to do the homework for you  :icon_mrgreen:
Ambition is a lame excuse for the ones not brave enough to be lazy, www.oby.ro

jlopezs104

Sorry i'm new in the forums my program is this:
.386
      .model flat, stdcall
     .STACK 64;16
      option casemap :none   ; case sensitive
.nolist
      include \masm32\include\windows.inc
      include \masm32\include\user32.inc
      include \masm32\include\kernel32.inc
      include \masm32\include\masm32.inc
    
.list
      includelib \masm32\lib\user32.lib
      includelib \masm32\lib\kernel32.lib
      includelib \masm32\lib\masm32.lib
      includelib \masm32\lib\oleaut32.lib
    .data
    arreglob db 1,4,2
   
    .code
    start:
    mov esi,OFFSET arreglob
   mov al,[esi]
   inc esi
   inc ecx
   mov al,[esi]
   ;mov arreg[esi]
   invoke ClearScreen
   
   
   INVOKE  nrQsortA,offset arreglob,3
   invoke locate,10,10
   invoke StdOut,ADDR arreglob
   
   
   invoke ExitProcess,0
    end start

i dont now what is the problem because the program dont print

P.D sorry for my english i'm latinamerican and my english is poor

dedndave

remove the .STACK directive for Flat models

if you are going to INCLUDELIB oleaut32.lib, you should also INCLUDE oleaut32.inc
i don't think either is needed, in this case

    arreglob db 1,4,2
i am pretty sure the routine is designed to sort DWORD's - not BYTE's
    arreglob dd 1,4,2

you have binary values in the array - not ASCII values
so - to diplay them you will want to convert them to ASCII decimal or ASCII hexidecimal (probably) strings
then display them
also - displayed strings should be zero-terminated

jlopezs104

Many thanks for your help dedndave I will do what you tell me and hopefully make my program work fine

Thanks a lot  :biggrin: :biggrin:

hutch--

Just note that "nrQsortA" is designed to sort DWORD sized numbers where your example is trying to sort byte sized data. If you need to sort byte data you either need to do some conversions or write a different algorithm. If you are required just to sort numbers, use DWORD sized data and any of the numeric sorts will work fine for you.



    myarray dd 10,9,8,7,6,5,4,3,2,1


When you call an array sort procedure you pass the address of the array, in this instance "OFFSET myarray" and you pass the count of array members, in this instance 10.

The advantage of using DWORD over BYTE is DWORD has a 4 billion number range where BYTE on has 256.

Vortex

Hi jlopezs104,

Here is a quick example :

include     \masm32\include\masm32rt.inc

NUMB_OF_MEMBERS equ 10


.data

array       dd 80,95,100,70,60,72,30,10,20,5
msg         db 'Member %d = %d',13,10,0


.code

start:

    call    main
    invoke  ExitProcess,0

main PROC uses esi ebx

    mov     esi,OFFSET array
    invoke  nrQsortA,esi,NUMB_OF_MEMBERS
    mov     ebx,1
@@:   
    invoke  crt_printf,ADDR msg,ebx,DWORD PTR [esi]
    add     ebx,1
    add     esi,4
    cmp     ebx,NUMB_OF_MEMBERS+1
    jnz     @b
    ret

main ENDP

END start


jlopezs104

thanks for your help with your example finished understand how the arrangement and function quicksort and the other sorting functions :biggrin: :biggrin: :biggrin: you saved my life