Java Reference
In-Depth Information
The position is a value from 0 to 8 , which points to a coin in the node, as shown in the
following figure.
A node is an
array of nine
characters
0
1
0
0
1
0
1
0
H
T
H
H
H
T
H
H
H
H
T
T
T
H
H
H
T
H
0
Position is 2
here in a node
For example, for node 56 in FigureĀ 28.19, flip it at position 0 , and you will get node 51 . If
you flip node 56 at position 1 , you will get node 47 .
The flipACell(char[] node, int row, int column) method flips a node at the
specified row and column. For example, if you flip node 56 at row 0 and column 0 , the new
node is 408 . If you flip node 56 at row 2 and column 0 , the new node is 30 .
511
1
111
11
11
1
408
488
240
30
47
51
1
011
10
1
101
11
0
110
11
0
011
00
0
101
00
0
110
00
00
0
00
0
00
0
11
0
11
1
01
1
0
111
00
00
56
0
F IGURE 28.19
If node u becomes node v after cells are flipped, assign an edge from v to u .
NineTailModel
#tree: AbstractGraph<Integer>.Tree
A tree rooted at node 511.
+NineTailModel()
+getShortestPath(nodeIndex: int):
List<Integer>
Constructs a model for the nine tails problem and obtains the tree.
Returns a path from the specified node to the root. The path
returned consists of the node labels in a list.
-getEdges():
List<AbstractGraph.Edge>
+getNode(index: int): char[]
+getIndex(node: char[]): int
+getFlippedNode(node: char[],
position: int): int
+flipACell(node: char[], row: int,
column: int): void
+printNode(node: char[]): void
Edge
Returns a list of
objects for the graph.
Returns a node consisting of nine characters of Hs and Ts.
Returns the index of the specified node.
Flips the node at the specified position and its adjacent positions
and returns the index of the flipped node.
Flips the node at the specified row and column.
Displays the node on the console.
F IGURE 28.20
The NineTailModel class models the nine tails problem using a graph.
 
Search WWH ::




Custom Search