Results 1 to 3 of 3

Thread: how do you do a 3 dimensional array

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2002
    Location
    Kentl
    Posts
    7

    how do you do a 3 dimensional array

    Code:
    What the right way to declare a 3 dimensional array
    i.e
     depot name   bus no       destination         journey time
    crewe	       80a	         London	     120
    crewe	        70	        liverpool                 90
    crewe	       60b	        Newcastle	      50
    Manchester    40c	        Glasgow	      90
    Glasgow	      40c	        leeds	      45
    
    Would it be
    
    String[] buses = {{ crewe ,        80a,    London,	120},
       {crewe,           70,      Liverpool,        90},
       {crewe,           60b,    Newcastle,       50},
       {Manchester,   40c,	 Glasgow,  	90},
       {Glasgow,       40c,	   leeds	,	45},};
    
    is  it the way you would do it, because each depot could have up to 5 buses
    leaving each day, I would have to leave room for 5 buses in each depot
    this must be wrong. As I would end up with
    
                              {{ crewe ,        80a,    London,	120},
                              {crewe,           70,      Liverpool,        90},
                              {crewe,           60b,    Newcastle,       50},
                              {crewe,           0,         0,                        0},
                              {crewe,           0,         0,                        0},
    
    3 depots using 15 rows * 4 colums is that right

  2. #2
    Addicted Member Phenix's Avatar
    Join Date
    Sep 2002
    Location
    Near A Cube
    Posts
    228

    Thumbs up

    You will need three sets of brackets [] to use a 3D array.
    String[][][] threeD; // threeD is a 3D array.
    See http://vbforums.com/showthread.php?threadid=221865

    private static boolean[][][] blockLook = {
    { { true, true, true, true},
    {false, false, false, false} },

    { { true, true, true, false},
    { true, false, false, false} },

    { { true, false, false, false},
    { true, true, true, false} },

    { {false, true, true, false},
    { true, true, false, false} },

    { { true, true, false, false},
    {false, true, true, false} },

    { {false, true, false, false},
    { true, true, true, false} },

    { { true, true, false, false},
    { true, true, false, false} }
    };

    When I first replied there, I didn't realize that the comments were showing a graphic for true and false, so I left out the comments here. This is a 7x2x4 array. It looks like you want a 3x15x4 array.

  3. #3
    New Member
    Join Date
    Dec 2002
    Posts
    2
    thanks Phenix

    I will go to bed now and have a go tomorrow again, well I wish you all out their a good night

    Lindsey

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