Announcement

Collapse

New Sub-Forum

In an effort to help make sure there are appropriate categories for topics of discussion that are happening, there is now a sub-forum for databases and database programming under Special Interest groups. Please direct questions, etc., about this topic to that sub-forum moving forward. Thank you.
See more
See less

Problem with ARRAY SORT

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

  • Problem with ARRAY SORT

    Hi
    It appears that I am having problem with ARRAY SORT. I generate a
    list of random numbers then have the compute sort them using ARRAY
    SORT. I then wish to use the first four lowest numbers. However, I
    have noticed that generally one of the four wanted numbers is the
    last one in the unsorted list of numbers BUT when I come to check
    the sorted list it is not in the list of four least numbers. An
    example of a recent list is a follows:
    beginning of unsorted list
    222
    461
    215
    552
    508
    344
    end of unsorted list
    beginning output of sorted list
    215
    222 (344 should come after 222)
    461
    508
    end of sorted list
    I have made a number of runs and with the same results the last number
    in the unsorted list isn't included in the sorted list.
    Any help?
    Fred Katzel



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

  • #2
    By chance have you ommitted observing that arrays can start
    with the (0)'th element and left to it's own devices, PowerBASIC
    expects you to be using it that way?

    I think you can move it up to start at the (1)'st element by
    setting OPTION BASE to 1, but it takes your effort to get it
    moved there, one way or another...

    Just thinking out loud.

    ------------------
    Mike Luther
    [email protected]
    Mike Luther
    [email protected]

    Comment


    • #3
      I think Mike hit the nail on the head here... there are absolutely no known or reported issues with ARRAY SORT, except those that are found to be program(mer) errors.

      If you DIM an array like so:
      DIM A%(10)
      you actually get 11 subscripts {A%(0) to A%(10)}, so an array sort like:
      ARRAY SORT A%() FOR 10
      will omit the 11th subscript in the array {A%(10)} from the sort.
      Another common mistake is to use:
      ARRAY SORT A%(1) FOR 10
      which leaves the 1st subscript out of the sort {A%(0)}

      Failing this, please post an example that shows your problem... thanks!


      ------------------
      Lance
      PowerBASIC Support
      mailto:[email protected][email protected]</A>
      Lance
      mailto:[email protected]

      Comment


      • #4
        Hi
        Thanks to Mike and Lance. I was aware that arrays can begin with 0.
        However, the manual doesn't show that. I was following the manual.
        I have update the manual to refect this.
        Thanks again.
        Fred

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

        Comment


        • #5
          Save the trouble. When you fill your array, use a for loop

          for m%=lbound(array%) to ubound(array%)
          array%(m%)=RND(0) 'Example
          next



          ------------------
          Amos

          Comment

          Working...
          X