Ordering an array in a 'strange' order.

This is a discussion on Ordering an array in a 'strange' order. within the C++ Programming forums, part of the General Programming Boards category; Hello there. Im new to the forum, this is my first post, it will be quick i guess =] I ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    3

    Ordering an array in a 'strange' order.

    Hello there. Im new to the forum, this is my first post, it will be quick i guess =]

    I want to read an array in a different order and cant think the algh to do that. Heres what i wanna do in a [3][3] simple example. The array AWAYS will be a square. (x=y)

    Code:
      int array[3][3] = {{4,2,1},
                         {7,5,3},
                         {9,8,6}};
    Lets say i want to printf() the array number in the normal order ( 1 2 3 4... ). How could i do the algh that does this ?

    This way i could generate 5 lines.

    1
    2 - 3
    4 - 5 - 6
    7 - 8
    9

    and that is what im after. Thanx for any replys.

    []īs Ziden

  2. #2
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    435
    There was a thread on this recently.
    zigzag traverse a matrix
    Last edited by NeonBlack; 05-11-2010 at 01:12 AM.
    I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    3
    thx for the reply.

    He made a zig zag order, witch i belive is harder then what ive expecting, and not functional to what im intenting to do. Ill give a look and study his code but i belive is beyond my intellect to do this, thats y im desperate for help =(

    What i really need is to 'walk' thro the array in that order and separate each line as i mentioned.
    Last edited by Ziden; 05-11-2010 at 01:31 AM.

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    3
    I figured out a simple way to solve this but still i cannot solve it, its impressive.

    If j is controllin the matriz colums, the idea of inverting it would be instead of using J, using MaxJ - J so i would invert the colum side of reading order, but i just cant do it... ive tryed many ways n cannot do it. I beg for help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Returning an object with a dynamic pointer
    By maxsthekat in forum C++ Programming
    Replies: 11
    Last Post: 09-16-2009, 01:52 PM
  2. 2d array question
    By gmanUK in forum C Programming
    Replies: 2
    Last Post: 04-21-2006, 12:20 PM
  3. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 12:01 AM
  4. Creating 2D arrays on heap
    By sundeeptuteja in forum C++ Programming
    Replies: 6
    Last Post: 08-16-2002, 11:44 AM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21