View Single Post
Old Sep 18th, 2007, 10:42 PM   #9
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 347
Rep Power: 4 cwl157 is on a distinguished road
alright so now if i wanted to make a tree with one child and then the child having up to 3 siblings all consisting of GridNodes but each int[][] state of the GridNodes would be different, how would i do that. I get the firstChild points to the child and then the nextSibling would point to the sibling and then i set those to null when i first create the instance and then when needed set them but i need to keep track of what level of the tree im in and all that too. I'm just really lost when it comes to trees so i took a class that deals with them hoping to learn only to find out today that the teacher doesn't help anyone so im actually kinda lost right now.

Alright so this is what i got on how to get it to work like i want it to
 int[][] initialState = {{7, 6, 4},
                             {8, 5, 2},
                             {1, 0, 3}
                            };
      
       //int[][] childState = parent.copy(parent.getState());
      GridNode parent = new GridNode(initialState, null, null);
      int[][] childState = parent.copy(parent.getState());
       GridNode child = new GridNode(childState, null, null);

but now i ask if im gonna be creating a bunch of children, is there a way for me to do it without having to create a new corresponding int[][] along with it? Because then to refer to it instead of saying child.getState() to get the state couldnt i just not even use the class and just create a new int [][] within this class and just refer to that for everything?
cwl157 is offline   Reply With Quote