Given the following graph Give the adjacency matrix for this


Given the following graph: Give the adjacency matrix for this graph Give the adjacency list for this graph Classify this graph based on number of edges. Write a C++ program that will take the adjacency matrix as input, and from this list you should be able to identify each edge and the corresponding weights. Your output from this program should be edge names and the corresponding weights. Input should be the matrix. For edge name, you can use strings and names can be given as 01, 34 using the two extreme vertices. Also remember 01 and 10 are same edges. You need to extract only distinct edges. Must attach the cpp code separately.

Solution

Please find the C++ program for the above

/* C++ program were the adjancy matrix in the list as the input*/

/* including the libaries files*/

#include<iostream> // std input and output files

#include<Stdio.h>

#inclue<conio.h>

using namespace std;

struct node // crestion of the structure with the name node

{

int from,to; //variable declaration in form of integer

} a[5] ,t; //global variable declaration

void addEdges(int am[][6],int i, int in, int j) // adding the edges, along witht eh variable declarations

{

a[in].from = i //getting the value from i

a[in].to = j //moving the value to j

for(int r=0;r<=in ; r++) //creation of the nested for loop

{

for ( intp=r+;p<=in;p++)

{

if (a[r].from >a[p].from)

{

t=a[r];

a[r] = a[p];

a[p] = t;

} //if loop is getting closed

else if (a[r].from == a[p].from)

{

if(a[r].to>a[p].to)

{

t=a[r];

a[r] = a[p];

a[p] = t;

}

}

else

{

continue;

}

}

}

}

}

}

int main () //this main class is getting created for vertices

{

/* varaible declaraion

int n,c=0 ,x,y,ch,i,j;

/* printing statement in the screen*/

cout <<\"enter the number of vertices \ \"; \\*\ means the new line*\\

cin >>n; /* getting the user inpuit*/

int am [5],[5]; /* delcaration of the array*/

for (int i=0;i<5;i++)

  {

   for (int j=0 ; j<5;j++)

   {

   am[i][j] =0;

}

}

/* using the while loop*/

while(ch != -1) /* ch is the varainle value is not equal to -1*/

{

/* printing statement in the screen*/

cout <<\"Enter the nodes between which edges need to be intorduced\ \";

/* input statement to recieve the input from the user*/

cin>>x>>y; /* both the value for x as well as y will be obtained.

addEdge (am,x,y,c);

c++;

cout<<\"press -1 to exit the screen \ \"; /* info in realte to exit is provided.

/* input statement will recieve the value given by the user

cin >>ch;

}

for (int j=0; j<c ; j++){

am[a[j].from[j] = 1; /* checking the value as equal to 1

am[a[j].to][j] =1

/* in above two statements the vetices from were to were the edges are provided will be shown clearly*/;

}

for (int i=0; i<n;i++)

  {

for(int j=0; j<c;j++)

  {

   cout<am[i][j] <<\"\\t\";

}

\\cout<<end1;

}

getch(); /* function call statement untill the condition getting failes

}

 Given the following graph: Give the adjacency matrix for this graph Give the adjacency list for this graph Classify this graph based on number of edges. Write
 Given the following graph: Give the adjacency matrix for this graph Give the adjacency list for this graph Classify this graph based on number of edges. Write
 Given the following graph: Give the adjacency matrix for this graph Give the adjacency list for this graph Classify this graph based on number of edges. Write

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site