replacement column and row between two arrays?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • walaa maher
    New Member
    • Nov 2012
    • 1

    replacement column and row between two arrays?

    you have two arry and you want to replace the column of one of them to the row of another?
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Read this: http://bytes.com/topic/c/insights/77...rrays-revealed

    Pay particular attention to the section on how arrays are laid out in memory.

    Then post again if you still have a question.

    Comment

    • whodgson
      Contributor
      • Jan 2007
      • 542

      #3
      To do this I think the two arrays would need to be the same size and square. If you're not fussy about which row and column the following shows how you would go about this using one 4x4 2d array to interchange row2 and column2. Using two arrays follows the same principle.
      To change column2 into row2:
      swap element [0][1] with element [1][0]
      swap element [2][1] with element [1][2]
      swap element [3][1] with element [1][3]
      (element [1][1] is not moved as it is common to the column & row)

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        @whodgson:
        You would not use an array. Instead you would use a structure lke a chain-link table where the columns can be of unequal length.

        A chain-link table is a linked list where each node is itself a linked list. Replacement here is to delete the linked list at one node and replce it with another linked list There is no requirement that the two linked lists involved have the same number of nodes.

        Comment

        • whodgson
          Contributor
          • Jan 2007
          • 542

          #5
          to:weaknessforc ats. yes i am pretty weak on lists so will need to dig a bit. The PO (or is it OP) in this case specified that he/she had two arrays and simply wanted to swap a row in one with a column in the other. but I understand in principle what you are telling me and appreciate it.

          Comment

          Working...