Results 1 to 5 of 5

Thread: I need help on 2 dimensonal arrays!, any good sites?

  1. #1

    Thread Starter
    Registered User struntz's Avatar
    Join Date
    Aug 1999
    Location
    Brockway,Pa,USA
    Posts
    199

    Talking I need help on 2 dimensonal arrays!, any good sites?

    Hello everyone!!

    I was wondering if anyone here knew any good sites that explain two-dimensional arrays well? I've read 2 books(well not the whole thing but the 2 dimensional array part) one was Teach Yourself C++ in 21 days and the other was a book i bought. For some reason i can't get the hang of it!! Can someone explain to me what they are all about or have another good site that explains them?


    THanks for your time!!

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    To best see the use of a 2D array imagine a chess board. It is like a 2D coordinate system. To mark a field you need two values.
    The filed [8][8] would be in the corner. It can also be represented as field[64] but [8][8] is far more unsderstandable.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Following on from the whole "indirection" theme, a 2D array is basically an array of arrays. For example int x[8] is an array of 8 ints. int x[8][8] is an array of 8 int [x]s.

    Am I being clear? I hope so, but probably not because this is nasty stuff
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  4. #4

    Thread Starter
    Registered User struntz's Avatar
    Join Date
    Aug 1999
    Location
    Brockway,Pa,USA
    Posts
    199
    in this example:

    Code:
    void read(int a[] [5]);
    
    void print(const int a[] [5]);
    
    main()
    {
    int a[3][5];
    read(a);
    print(a);
    }
    
    void read(int a[][5])
    {
    //code
    }
    void print(const int a[][5])
    {
    //code
    }
    why don';t you have to say what the first element [ ] is? but u must say waht the 2nd one is.

    THe part i don't understand of 2 dimensional arrays is what each means....like for instance..what does this create?


    int a[4][5];

    does it create 4 groups of arrays with 5 elements in each array?

    like
    [][][][][]
    [][][][][]
    [][][][][]
    [][][][][]

    can u explain it with boxes?

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I'm not quite sure what your sample means, i usually don't use arrays, especially not multidimensional. If i'm correct you'd need to specify each but first dimension since to count the distance to an element from the first, you need all but the dimension which is wrapping the others, that is the first.

    To understand dimensions you need to understand what a scale is. A dimension is a scale with a unit, and if you have sets of elements (as you call them boxes) they are arrays of that dimension, the scale unit is an element. In a multidimensioned array the elements of the earlier dimension is containing all elements of the next dimension, so if the element you need to access is within the second element of the first dimension, the element is after the last element of the last dimension in the first element of the first dimension. IN a two dimensioned array, you could see it like this:

    [1][2][3][4][5]
    [6][7][8][9][10]

    where [1,0] is the 6'th element, just after the last element in the first.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width