Question
C++ question, I'm not sure how to use an unordered map to write this function. Template of the program that needs this function class graphType
C++ question, I'm not sure how to use an unordered map to write this function.
Template of the program that needs this function
class graphType { public: bool isEmpty() const; //Function to determine whether the graph is empty. //Postcondition: Returns true if the graph is empty; // otherwise, returns false.
void createGraph(); //Function to create a graph. //Postcondition: The graph is created using the // adjacency list representation.
void clearGraph(); //Function to clear graph. //Postcondition: The memory occupied by each vertex // is deallocated.
void printGraph() const; //Function to print graph. //Postcondition: The graph is printed.
void depthFirstTraversal(); //Function to perform the depth first traversal of //the entire graph. //Postcondition: The vertices of the graph are printed // using depth first traversal algorithm.
void breadthFirstTraversal(); //Function to perform the breadth first traversal of //the entire graph. //Postcondition: The vertices of the graph are printed // using breadth first traversal algorithm.
graphType(int size = 0); //Constructor //Postcondition: gSize = 0; maxSize = size; // graph is an array of pointers to linked // lists.
~graphType(); //Destructor //The storage occupied by the vertices is deallocated.
protected: int maxSize; //maximum number of vertices int gSize; //current number of vertices unorderedLinkedList
private: void dft(int v, bool visited[]); //Function to perform the depth first traversal of //the graph at a node specified by the parameter vertex. //This function is used by the public member functions //depthFirstTraversal and dftAtVertex. //Postcondition: Starting at vertex, the vertices are // printed using depth first traversal // algorithm. };
CycleFinder: traverse the graph and determine the node(s) that start cycle(s) in the graph. Use the unordered map data structure in the STL to keep track of the nodes that have been visited. Assumptions: Unique keys, Simple graphs with cycles (no weirdness), e.g., use the graph: 0 rightarrow 1 rightarrow 2 rightarrow 3 rightarrow 0 No need to worry about cases like 4 rightarrow 0 rightarrow 1 rightarrow 2 rightarrow 3 rightarrow 0 (unless you want to!)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