Home AMX User Forum AMX Technical Discussion
Options

sorting in Netlinx

Hello!

It´s a simple question:
Is there a "sorting" module or function to do "smart sorting" in NetLinx, like quicksort and so? Or should i implement a sorting algorithm by myself?

Thanks!

Comments

  • Options
    AMXJeffAMXJeff Posts: 450
    MorgoZ wrote: »
    Hello!

    It´s a simple question:
    Is there a "sorting" module or function to do "smart sorting" in NetLinx, like quicksort and so? Or should i implement a sorting algorithm by myself?

    Thanks!

    You will need to create your own sorting methods.
  • Options
    yuriyuri Posts: 861
    I have some samples I once got from somebody else... Can try to dig them up, thought it was a shellsort and a quicksort :)
  • Options
    DHawthorneDHawthorne Posts: 4,584
    A shell sort is easier to implement, and for the kinds of lists I have had to deal with, efficient enough to go with. I suppose if the list was enormous, I would go with a quick sort, but otherwise the shell is good enough.
  • Options
    Jorde_VJorde_V Posts: 393
    jjames wrote: »

    Thanks for that link, a very interesting read.
  • Options
    MorgoZMorgoZ Posts: 116
    Thanks for your replys!!!

    The link of jjames was really helpfull, i´m finally using a Shell sort.

    Here is the code of the Shell sort, which is the same as the Spire_Jeff´s. But i think that it could be useful to post the raw code; just the Shell sort algorithm, since the code posted at the link is not easy to understand at first sight

    <code>

    DEFINE_CONSTANT

    //GAPS for Sedgewick sequence
    GAPS[] = {1968, 861, 336, 112, 48, 21, 7, 3, 1}

    DEFINE_VARIABLE

    volatile integer numFind, indGap, nTemp, length_GAPS

    DEFINE_START

    length_GAPS = length_array(GAPS)


    (.......................................)

    /***** Shell Sort Algorithm ******/
    /*** for array A ***/

    numFind = length_array(A)
    indGap = 1

    while (GAPS[indGap] > numFind )
    {
    indGap++
    }

    while (indGap<= LENGTH_GAPS)
    {
    k = GAPS[indGap]

    for (i=k+1; i<=numFind ; i++)
    {
    j = i
    while (j > k && A[j-k] > A[j])
    {
    nTemp = A[j]
    A[j] = A[j - k]
    A[j - k] = nTemp

    j = j-k;
    }
    }
    indGap++;
    }
    </code>

    It can be also used for a string array.


    Salutes!!
  • Options
    MorgoZMorgoZ Posts: 116
    Sorry....... i didn´t know how to post the code inside a "code box"... if someone could help...

    Thanx!
  • Options
    AuserAuser Posts: 506
    MorgoZ wrote: »
    Sorry....... i didn´t know how to post the code inside a "code box"... if someone could help...

    Thanx!

    You can wrap code in a [ code ] [ /code ] block like:
    var someCode
    

    Don't put spaces between the brackets and the code and /code tags. If you get stuck, hit "Reply With Quote" on this post and it should show you how it's formatted.
Sign In or Register to comment.