Question
Write a C++ program called hw3_3 .cpp (or hw3_3.java) that converts a directed graph data from a user into a corresponding adjacency list format. Your
Write a C++ program called hw3_3.cpp (or hw3_3.java) that converts a directed graph data from a user into a corresponding adjacency list format. Your program should read an input graph data from a user. Then, your program should convert it to the adjacency matrix format. In the assignment, you can assume that the maximum number of vertices in the input graph is less than or equal to 50.
Input format: This is a sample input from a user.
|
The first line (= 3 in the example) indicates that there are three vertices in the graph. The second line (= 4 in the example) presents the number of edges in the graph. The remaining four lines are the edge information in the graph. For the homework, you shouldassume that the first vertex starts from the number 0. Thus, t1.txt describes a directed graph like below:
Sample Run 1: Assume that the user typed the following lines
3
4
0 1
0 2
2 1
2 0
This is the correct output of your program.
0->1->2
1
2->0->1
Note that the sequence of output values is important. For example, when you display the neighbor vertices of the vertex 0, the sequence should be 1 and then 2 (= ascending order). If your program displays 2 and then 1, its not correct. Similarly, for the vertex 2, your program should display 0 and then 1.
Sample Run 2: Assume that the user typed the following lines
5
5
2 3
3 4
1 2
0 2
2 4
This is the correct output of your program.
0->2
1->2
2->3->4
3->4
4
Note that this is the directed graph of the input data:
Sample Run 3: Assume that the user typed the following lines
3
6
0 1
1 0
1 2
2 1
2 0
0 2
This is the correct output of your program.
0->1->2
1->0->2
2->0->1
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started