Announcement

Collapse
No announcement yet.

Algorithm to reverse a 2d string array

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

  • Algorithm to reverse a 2d string array

    I'm looking for the fastest way to reverse a two dimensional strings array.

    The array is MyArray(Columns, Rows).

    I'm looking for a function that will return the array (or another array) in the reverse (or rotating dimension) i.e. MyArray(Rows, Columns).

    Do you think I can use some built in PowerBASIC functions for that purpose ?

    Thanks for your help.

    Jean-Pierre
    Jean-Pierre LEROY

  • #2
    https://www.powerbasic.com/help/pbcc/mat_statement.htm

    MAT a1() = TRN(a2())

    Comment


    • #3
      ?????

      As long as you have both 'rows' and 'columns' it should not matter in what order they appear (in which dimension they are stored), as you can process the array any way you like.

      Code:
      FOR Row = 1 TO  maxRow
      ..
         For col = 1 to maxCol
         NEXT
      NEXT
      .. will get the job done as well as will...

      Code:
      FOR Col = 1 TO  maxCol
      
         For Row = 1 to maxRow
         NEXT
      NEXT



      Michael Mattias
      Tal Systems Inc.
      Racine WI USA
      mmattias@talsystems.com
      http://www.talsystems.com

      Comment


      • #4
        Originally posted by Paul Dixon View Post
        Thank you very much Paul; it is exactly what I as looking for.

        Regards. Jean-Pierre.
        Jean-Pierre LEROY

        Comment


        • #5
          The OP said: I'm looking for the fastest way to reverse a two dimensional strings array.


          Does MAT = TRN work with string arrays?
          Help says:
          MAT CON, IDN ZER + - = and TRN operations are valid with Byte, Word, Double-word, Integer, Long-integer, Quad-integer, Single-precision, Double-precision and Extended-precisionarrays.
          --
          [URL="http://www.camcopng.com"]CAMCo - Applications Development & ICT Consultancy[/URL][URL="http://www.hostingpng.com"]
          PNG Domain Hosting[/URL]

          Comment


          • #6
            Oups, you're right. I have to find another solution for my two dimensional strings arrays.
            Jean-Pierre LEROY

            Comment


            • #7
              Originally posted by Michael Mattias View Post
              ... it should not matter in what order they appear (in which dimension they are stored), ...
              It matters if you need to pass the array to a function developed by a 3rd party (for example, a grid control).

              ~~~

              It's actually an interesting issue. Why doesn't MAT TRN work with string arrays? It just needs to transpose the string pointers. Shouldn't be any different from MAT TRN with Long integers, should it?

              Bernard Ertl
              InterPlan Systems

              Comment


              • #8
                Originally posted by Bern Ertl View Post

                It matters if you need to pass the array to a function developed by a 3rd party (for example, a grid control).

                ~~~

                It's actually an interesting issue. Why doesn't MAT TRN work with string arrays? It just needs to transpose the string pointers. Shouldn't be any different from MAT TRN with Long integers, should it?
                I'd guess it's because the whole MAT family were written as a group to handle "Matrix Arithmetic" where Matrix has the classical mathematical meaning of "an array of numbers".
                --
                [URL="http://www.camcopng.com"]CAMCo - Applications Development & ICT Consultancy[/URL][URL="http://www.hostingpng.com"]
                PNG Domain Hosting[/URL]

                Comment


                • #9
                  Tried JOIN$ and PARSE, but put elements in the wrong order.
                  This works, but not optimized.
                  https://forum.powerbasic.com/forum/u...lumn-row-array

                  Code:
                  https://forum.powerbasic.com/forum/user-to-user-discussions/programming/759422-reverse-column-row-array
                  
                  FUNCTION MakeRowColumnArray(OldArray() AS STRING,NewArray() AS STRING) AS LONG
                   LOCAL ROW,COL AS LONG
                   DIM newArray(LBOUND(OldArray,2) TO UBOUND(OldArray,2),LBOUND(OldArray,1) TO UBOUND(OldArray,1)) AS STRING
                   FOR ROW = LBOUND(OldArray,2)  TO UBOUND(OldArray,2)
                    FOR COL = LBOUND(OldArray,1)   TO UBOUND(OldArray,1)
                     NewArray(ROW,COL) = OldArray(COL,ROW)
                    NEXT
                   NEXT
                  END FUNCTION



                  Last edited by Mike Doty; 22 Mar 2017, 04:53 AM.

                  Comment

                  Working...
                  X