Announcement

Collapse
No announcement yet.

I will need QuickSort routine

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Nedal Qunibi
    Guest replied
    hi stephane ,

    try this one i think it is the fastest

    in DECLAREATION write this( PUBLIC C$),

    in the procedure write this.

    i = 1
    FOR i% = 0 TO 255
    C$ = C$ + CHR$(i%)
    NEXT i%

    AND USE THIS
    ARRAY SORT (NAME OF WHAT YOU WANT TO SORT) , COLLATE C$


    ------------------

    Leave a comment:


  • mark smit
    Guest replied
    Hello Stephane,

    Here is another quicksort...

    Code:
    sub qsort(dat() as long, l as long, r as long)
        local i as long
        local j as long
        local m as long
    
        i = l
        j = r
        m = dat((l+r)\2)
    
    
        while (i<=j)
            while dat(i)<m: incr i: wend
            while dat(j)>m: decr j: wend
    
            if (i<=j) then
                swap dat(i),dat(j)
                incr i
                decr j
            end if
        wend
    
    
        if (l<j) then qsort dat(),l,j
        if (i<r) then qsort dat(),i,r
    end sub
    
    
    called: qsort array(),lbound(array),ubound(array)
    ------------------
    Cheers

    Leave a comment:


  • john writer
    Guest replied
    ---------Example---------
    TYPE sortar
    Length AS integer
    data as byte
    END TYPE

    DIM SortArray(1 TO 1000) AS shared sortar
    Defint A-Z

    QuickSort 1,1000

    End


    SUB QuickSort (low as integer, high as integer)
    IF low < high THEN
    IF high - low = 1 THEN
    IF SortArray(low).Length > SortArray(high).Length THEN
    SWAP SortArray(low), SortArray(high)
    END IF
    ELSE

    ' Pick a pivot element at random, then move it to the end:
    RandIndex = RandInt(low+0, high+0)
    SWAP SortArray(high), SortArray(RandIndex)
    Partition = SortArray(high).Length
    DO

    ' Move in from both sides towards the pivot element:
    I = low: J = high
    DO WHILE (I < J) AND (SortArray(I).Length <= Partition)
    I = I + 1
    LOOP
    DO WHILE (J > I) AND (SortArray(J).Length >= Partition)
    J = J - 1
    LOOP

    ' If we haven't reached the pivot element, it means that two
    ' elements on either side are out of order, so swap them:
    IF I < J THEN
    SWAP SortArray(I), SortArray(J)
    END IF
    LOOP WHILE I < J

    ' Move the pivot element back to its proper place in the array:
    SWAP SortArray(I), SortArray(high)

    ' Recursively call the QuickSort procedure (pass the smaller
    ' subdivision first to use less stack space):
    IF (I - low) < (high - I) THEN
    QuickSort low, I - 1
    QuickSort I + 1, high
    ELSE
    QuickSort I + 1, high
    QuickSort low, I - 1
    END IF
    END IF
    END IF
    END SUB


    ------------------

    Leave a comment:


  • Ian Cairns
    replied
    Do a search on quicksort. There is at least one in the DOS forum and one in the Source Code forum.

    Regards,

    ------------------
    [email protected]

    Leave a comment:


  • Mel Bishop
    replied
    Is there some reason you need to write your own QuickSort
    routine? PB's Array Sort is just about the fastest sort
    you can get on the market and it works with both numeric and
    string arrays.


    ------------------

    Leave a comment:


  • stephane fonteyne
    Guest started a topic I will need QuickSort routine

    I will need QuickSort routine

    Hi programmers,

    Is there someone help me how I can writing the algoritm QuickSort routine?

    Greetings,
    Stephane


    ------------------
Working...
X