Sorting arrays


Closed Thread
Results 1 to 7 of 7

Thread: Sorting arrays

Hybrid View

  1. #1
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,172


    Did you find this post helpful? Yes | No

    Default Re: Sorting arrays

    Off the top of my head again, what if you concatenate the numbers?

    510512
    511512

    No matter what you have in the last 3 positions, 510 will always be in front of 511.

    Robert

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

    Default Re: Sorting arrays

    Maybe for every entry have an array of 4 words?

    Sorting based on the second element of the array.

    Ioannis

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Sorting arrays

    Thanks for the feedback.

    Demon, not sure I follow your idea?

    Ioannis, I think this is the way. An array of arrays.
    Are you suggesting a 4 word array as a Long variable?

    Every data base or logger must deal with this problem. So I'm sure there
    is a standard way. Most examples show the data being processed in a
    pc using excel or VB and not in a pic.

    Thanks again

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Sorting arrays

    As you move the AN0 samples, move the AN1 samples the same way...
    Code:
    SAMPLE_AN0 WORD [12]
    SAMPLE_AN1 WORD [12]
    CounterA var BYTE
    DataTemp var WORD
    Getsamples:
     For A = 1 to 12
      adcin 0 SAMPLE_AN0[A]
      adcin 1 SAMPLE_AN1[A]
     NEXT A
    Sortdata: 'THIS WILL SORT SAMPLES_AN0
    CounterA=0
    SortArrayLoop:
    If SAMP_AN0[CounterA+1] < SAMP_AN0[CounterA] then
        DataTemp = SAMP_AN0[CounterA]
        SAMP_AN0[CounterA] = SAMP_AN0[CounterA+1]
        SAMP_AN0[CounterA+1]= DataTemp
        DataTemp = SAMP_AN1[CounterA]
        SAMP_AN1[CounterA] = SAMP_AN1[CounterA+1]
        SAMP_AN1[CounterA+1]= DataTemp
    If CounterA > 0 then CounterA = CounterA - 2
        endif
        CounterA = CounterA + 1
    If CounterA < 11 then goto SortArrayLoop
    END
    DT

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: Sorting arrays

    Darrel,

    Thank you for the answer!

    Regards

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

    Default Re: Sorting arrays

    As Darrel replied, there is no need for a long variable. Besides you have 4 discrete variable that you have to treat as a whole.

    Ioannis

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts