Question
Implement a data structure to represent a directed graph (collection of nodes and directed edges) with the following properties. Each node in the graph has
Implement a data structure to represent a directed graph (collection of nodes and directed edges) with the following properties. Each node in the graph has a one character label. There cannot be two nodes with the same label. Each edge will have an origin node and a destination node. A node can be the origin for at most three edges (example A B, A C, A+D). A node cannot be the origin and destination of the same edge (example A+A). There can not be more than one edge with the same direction between two nodes (example ABB and A+B). But there could be edges of opposite directions between two nodes (example A B and BAA). A node could be the destination for many edges. There could be nodes that are not connected to any other node in the graph (they are neither the origin nor the destination for any edge). Implement the data structure in one or more classes (no more than 4 classes). Hint: you could implement a class for representing the nodes and edges, and one for the graph as a list or collection of nodes. Implement at least the methods to have the following functionality: Constructor that create an empty graph (no nodes and edges); Add a node to the graph with a specified label; Change the label of a node; Delete a node from the graph (and all the edges that are connected to it); Create an edge between two nodes (one is the origin and one is the destination); Delete an edge between two nodes; Display all the immediate neighbors of a node. An immediate neighbor to a node A is a node that is connected by an edge (regardless of its direction) with node A. Display all the nodes in the graph through their label. Display all the edges in the format A>B, where A is the origin node and B is the destination node. Other methods or classes are not required, but are not prohibited either. Write a test program that will use the above data structure use all of the above-mentioned methods and displays the results to demonstrate the ren,uired functionality. You are encouraged to use simple I/O (cin and cout) rather than a graphical user interface.
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