Announcement

Collapse
No announcement yet.

Algorithm to reverse a 2d string array

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

  • Jean-Pierre LEROY
    started a topic Algorithm to reverse a 2d string array

    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

  • Mike Doty
    replied
    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.

    Leave a comment:


  • Stuart McLachlan
    replied
    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".

    Leave a comment:


  • Bern Ertl
    replied
    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?

    Leave a comment:


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

    Leave a comment:


  • Stuart McLachlan
    replied
    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.

    Leave a comment:


  • Jean-Pierre LEROY
    replied
    Originally posted by Paul Dixon View Post
    Thank you very much Paul; it is exactly what I as looking for.

    Regards. Jean-Pierre.

    Leave a comment:


  • Michael Mattias
    replied
    ?????

    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



    Leave a comment:


  • Paul Dixon
    replied
    https://www.powerbasic.com/help/pbcc/mat_statement.htm

    MAT a1() = TRN(a2())

    Leave a comment:

Working...
X