Question
Please help me with this C++ problem. In the c++ code below, I have created a connected graph with 9 vertices. I only know how
Please help me with this C++ problem. In the c++ code below, I have created a connected graph with 9 vertices. I only know how to represent the graph with adjacency list, but I need to write a function that is able to print each node of the graph in the following way:(1st row: 1 2 3, 2nd row: 4 5 6, 3rd row: 7 8 9).
This is my code:
#include #include using namespace std;
int main() { vector adj[100]; int n=9;/umber of vertices. adj[1].push_back(2); adj[2].push_back(1); adj[1].push_back(4); adj[4].push_back(1); adj[2].push_back(3); adj[3].push_back(2); adj[2].push_back(5); adj[5].push_back(2); adj[3].push_back(6); adj[6].push_back(3); adj[4].push_back(5); adj[5].push_back(4); adj[4].push_back(7); adj[7].push_back(4); adj[5].push_back(6); adj[6].push_back(5); adj[5].push_back(8); adj[8].push_back(5); adj[6].push_back(9); adj[9].push_back(6); adj[7].push_back(8); adj[8].push_back(7); adj[8].push_back(9); adj[9].push_back(8); //print the graph with adjacency list. for(int i=1;i"
Thank you so much.
||1 |2| 3| | 4| 5 |6| |71819 | - - - - - - - - - - ||1 |2| 3| | 4| 5 |6| |71819 |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