Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please check the full picture ,all information is given. I can't upload the codes as it is showing that my text is too long.Please try

image text in transcribedPlease check the full picture ,all information is given. I can't upload the codes as it is showing that my text is too long.Please try to solve from here. AND THE CODE MUST BE DONE IN C++ .

THE CODE MUST BE DONE IN C++. I CAN'T UPLOAD THE CODES IN TEXT FORM IT IS SHOWING THAT MY QUESTION IS TOO LONG.Please try to solve from here. 2. [26 points] Given the graph bellow- a) Write a function to count total number of prime nodes and print them. b) Write a function to print the nodes which are not adjacent with node 5. // DFS algorithm void Graph::DFSint vertex) { visited[vertex] = true; list int> adjList = adjLists[vertex]; cout iterator i; for (i = adjList.begin(); i != adjList.end(); ++i) if (!visited[*i]) DFS(*1): } void Graph::printGraph( int V) { for (int v = 0; v" #include using namespace std; class Graph { int numVertices; list *adjLists; bool *visited public: Graph(int V); void addEdge(int src, int dest); void DFS(int vertex): void printGraph(int V): }; int main() { Graph g(9): g.addEdge(0, 1); g.addEdge(0, 8): g.addEdge(0.7): g.addEdge(1,8); g.addEdge(2,8); g.addEdge(2, 4); g.addEdge(3, 2); g.addEdge(5.4); g.addEdge(5.8); g.addEdge(5.3); g.addEdge(6,5); g.addEdge(7,6); g.addEdge(7,5); g.addEdge(8.3); g.DFS(O): g.printGraph(9); return 0; } // Initialize graph Graph::Graph(int vertices) { numVertices = vertices; adjLists = new list int>[vertices]; visited = new bool(vertices]; } // Add edges void Graph::addEdge(int src, int dest) { adjLists[src).push_front(dest): }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Genetic Databases

Authors: Martin J. Bishop

1st Edition

0121016250, 978-0121016258

More Books

Students also viewed these Databases questions