Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please write in C++ code Strictly. DO not write in other languages. Also, please don't use STL. Write a C+ or Java class definition for
Please write in C++ code Strictly. DO not write in other languages. Also, please don't use STL.
Write a C+ or Java class definition for an abstract data type called Graph that models an undirected graph. Some implementation details: .Loops are allowed but multiple edges are not allowed. Vertices are labeled by number from 0 to n-1 where n is the number of vertices in the graph Implement the following public member functions. A constructor that creates an empty graph. An appropriate destructor. No need if you use Java. void load (char *filename): Creates the graph using the file passed into the function. The format of the file is described later. You may assume load is only called once for a graph. You may modify the argument type of this function if you use Java. void display () : Displays the graph's adjacency matrix to the screen .void displayDFS (int vertex): Displays the result of a depth first search starting at the provided vertex. When you have a choice between selecting two vertices, pick the vertex with the lower number. .void displayBFS (int vertex): Displays the result of a breadth first search starting at the provided vertex. When you have a choice between selecting two vertices, pick the vertex with the lower number. You are permitted to add extra member functions you feel are helpful. DFS must be implemented using recursion. You can use "queue" in STL in the implementation of BFS. Other forms of using STL are not permitted. Input File Format The function load is responsible for reading in a file corresponding to a graph. The format is as follows The first line contains a single integer indicating how many vertices are present in the graph. You may make no assumptions on how many vertices in the graph this means that your constructor will have to use dynamic allocation. All remaining lines contain two integers that indicate an edge connects the two vertices You can assume that the file exists and is well formed aple, the following graph is represented by the file 0 1 3 2 4 0 Test Driver Program The program must accept the name of an input file as a command line argument. Create a main function that does the following: 1. 2. 3. 4. 5. Create an empty graph Loads the graph using the specified input file. Display the adjacency matrix Display a depth first search starting at vertex 0 Display a breadth first search starting at vertex 0 Program Output Here is the output for the four provided input files grapho.txt: Adjacency Matrix 0 01100 0 01110 1100 01 1100 011 0 100011 0 01110 0 0011 0 0 DFS at vertex 0: 0 213 546 BFS at vertex O:0 231 5 6 4 graphl.txt: Adjacency Matrix 01001 10110 0101 1 011 0 1010 DFS at vertex 0: 012 34 BFS at vertex 0: 0 14 2 3 graph2.txt: Adjacency Matrix 010 100O0 101110 000 0 10 001O0 110 010100 010 10101 0 01010011 0 0010001 0 00011101 0 0000101 DFS at vertex O:0125 436 78 BFS at vertex O:0132465 78 graph3.txt Adjacency Matrix 011110 101011 1101 o 10101 1 1101 0 1 01011 0 DFS at vertex 0:012345 BFS at vertex 0:012345Step 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