Question
- Display a friendly greeting to the user
- Prompt the user for the name of a file specifying a graph
- Accept that file name Attempt to open the file
- On failure, notify the user and exit
- Read the data from the file
- Create the Adjacency matrix
- Display the Adjacency Matrix
- Create the Path Matrix
- Display the Path Matrix
- *Use Warshalls Algorithm
Text in File: A = {1,2,3,4,5,6,7,8,9} R = {<1,2>,<2,6>,<6,2>,<5,1>,<6,5>,<3,2>,<6,3>,<3,7>,<8,7>,<9,9>}
Text in File: A = {1,2,3,4,5,6,7,8,9} R = {<1,2>,<2,6>,<6,2>,<5,1>,<6,5>,<3,2>,<6,3>,<3,7>,<8,7>,<9,9>} A = {1,2,3,4,5,6,7,8,9} R = {<1,2>,<2,6>,<6,2>,<5,1>,<6,5>,<3,2>,<6,3>,<3,7>,<8,7>,<9,9>}
Explanation / Answer
class AdjacencyMatrix { public static void main(String[] args) { int V = Integer.parseInt(args[0]); int E = Integer.parseInt(args[1]); boolean adj[][] = new boolean[V][V]; for (int i = 0; i < V; i++) for (int j = 0; j < V; j++) adj[i][j] = false; for (int i = 0; i < V; i++) adj[i][i] = true; for (In.init(); !In.empty() ;) { int i = In.getInt(), j = In.getInt(); adj[i][j] = true; adj[j][i] = true; } } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
class AdjacencyMatrix { public static void main(String[] args) { int V = Integer.parseInt(args[0]); int E = Integer.parseInt(args[1]); boolean adj[][] = new boolean[V][V]; for (int i = 0; i < V; i++) for (int j = 0; j < V; j++) adj[i][j] = false; for (int i = 0; i < V; i++) adj[i][i] = true; for (In.init(); !In.empty() ;) { int i = In.getInt(), j = In.getInt(); adj[i][j] = true; adj[j][i] = true; } } } class AdjacencyMatrix { public static void main(String[] args) { int V = Integer.parseInt(args[0]); int E = Integer.parseInt(args[1]); boolean adj[][] = new boolean[V][V]; for (int i = 0; i < V; i++) for (int j = 0; j < V; j++) adj[i][j] = false; for (int i = 0; i < V; i++) adj[i][i] = true; for (In.init(); !In.empty() ;) { int i = In.getInt(), j = In.getInt(); adj[i][j] = true; adj[j][i] = true; } } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
class AdjacencyMatrix { public static void main(String[] args) { int V = Integer.parseInt(args[0]); int E = Integer.parseInt(args[1]); boolean adj[][] = new boolean[V][V]; for (int i = 0; i < V; i++) for (int j = 0; j < V; j++) adj[i][j] = false; for (int i = 0; i < V; i++) adj[i][i] = true; for (In.init(); !In.empty() ;) { int i = In.getInt(), j = In.getInt(); adj[i][j] = true; adj[j][i] = true; } } }