#include<iostream>
using namespace std;
struct graph
{
int V;
int E;
int **adj;
};
graph* adjmatrix()
{
int v,i,u;
graph *temp=new graph;
cout<<"enter number of nodes ";
cin>>temp->V;
cout<<"enter numbers of edges ";
cin>>temp->E;
int **arr=new int*[temp->V];
for(i=0; i<temp->V; i++)
{
arr[i]=new int[temp->V];
}
temp->adj=arr;
for(u=0; u<temp->V; u++)
{
for(v=0; v<temp->V; v++)
{
temp->adj[u][v]=0;
}
}
for(i=0; i<temp->E;i++)
{
cout<<"Enter nodes of vertex["<<i<<"] ";
cin>>u>>v;
temp->adj[u][v]=1;
temp->adj[v][u]=1;
}
return temp;
}
void show(graph *ptr)
{
int i,j;
graph *temp=ptr;
cout<<"atbtctdn";
for(int i=0; i<temp->V;i++)
{
for(j=0;j<temp->V;j++)
{
cout<<temp->adj[i][j]<<"t";
}
cout<<"n";
}
}
int main()
{
int i,j;
graph *ptr=NULL;
ptr=adjmatrix();
show(ptr);
return 0;
}
0 Comments