2uzhan.com
Advertisement
Now Place:2uzhan.com » How do I navigate a 3-D array?

How do I navigate a 3-D array?

Software Development @ February 7, 2011   Views:0

I'm required to construct a three-dimensional array (a "universe"), but unlike traditional array navigation where you go to the end of the column, row, etc., increment and start at the beginning, I am required to move in reverse (like actually navigating a cube). The precise instructions:

- Move along a row (through the columns) until it comes to a side edge
- Move one layer deeper and then travel back along the row until it is back at a side edge
- Repeat these movements until the back edge is reached. Then move down to the next row.
- Move along a row (through the columns) until it comes to a side edge
- Move one layer forward and then travel back along the row until it is at a side edge
- Repeat the last 2 movements until the front edge is reached. Then move down to the next
row.
- Now repeat ALL of the above until the universe is exhausted

My code is as follows, though it may be hard to interpret. The loop structure follows the desired pattern perfectly until x=1, y=1, and z=0. What's happening here that causes this error? How can I fix it? Note: I cannot use any API classes.

public static void searchUniverse(int array[][][]){
        int columnInverse=0, depthInverse=0, rowInverse=0, row=0, column=0, depth=0;
        for (int x=0; x<array.length; x++){          //row 1 --> 1
            for (int y=0; y<array[x].length; y++){       //depth 0 --> 1
                depthInverse=array[x].length;
                if (x%2==0)
                    depthInverse=2*y+1;
                for (int z=0; z<array[y].length; z++){   //column 2 --> 0
                    columnInverse=array[y].length;
                    if (y%2==0 && x%2==0)
                        columnInverse=2*z+1;
                    System.out.println(x+" Row\t\t"+(x+1)+"\n"+y+" Depth\t\t"+(depthInverse-y)+"\n"+z+" Column\t"+(columnInverse-z)+"\n");
                }
            }
        }
    }

--------------Solutions-------------

Before I get into the specific issues, I want to provide some other details:

  • Normally, I work on a live, paid server (even in dev); I realize that is ...

Yes, WPF. The learning curve is steep, but what amazing things you can do with it!
Look at this hexagon window for instance. Serves no purpose in a business environment ...

Hey there,

I am trying to create a register code. So basicly im making a quiz and every time a user starts up my program he/she needs to register (making ...

© 2018 2uzhan.com Contact