This Java program reads graph data from an input file and performs a Breadth-First Search (BFS) algorithm on each graph. The program is capable of handling edge inputs across multiple lines.
- Open a terminal or command prompt.
- Navigate to the directory containing the Java source files (
Prog1.java
). - Compile the Java files using the
javac
command: - Example: javac Prog1.java Graph.java Point.java Edge.java
- After successful compilation, run the program using the
java
command followed by the name of the main class (Prog1
) along with the classpath: - Example: java -classpath . Prog1 input_file.txt
Replace input_file.txt
with the path to your input file containing graph data. Though an example 'input_file.txt' is included.
- The program will process the graph data from the input file and perform BFS on each graph, printing the traversal results to the console.
The input file should contain graph data in the following format:
Each edge should be represented as a pair of vertices enclosed in parentheses and separated by a comma, e.g., (1,2)
.
Example input file:
5 (1,2) (3,4) (3,5) (4,5) 4 (1,2) (2,3) (1,4)
NOTE: All verticies and edges are on the same line for each graph.
The program will print the BFS traversal result for each graph, with each graph separated by an empty line.