#include<iostream>
using namespace std;
class node
{
public:
char data;
node *start = NULL;
node *next;
void list(char ch)
{
node *ptr = new node;
node *temp = new node;
ptr->data = ch;
if(start == NULL)
{
start = ptr;
start->next = NULL;
}
else
{
temp = start;
while(temp->next != NULL)
{
temp = temp->next;
}
ptr->next = NULL;
temp->next = ptr;
}
}
void displaylist()
{
node *temp = new node;
if(start == NULL)
{
cout<<"LIST IS EMPTY"<<endl;
}
else
{
temp = start;
while(temp != NULL)
{
cout<<temp->data<<"->";
temp = temp->next;
}
cout<<endl;
}
}
};
class graph
{
int a[10][10];
char arr[5] = {'A','B','C','D','E'};
int vertices;
node al[5];
public:
graph()
{
cout<<"ENTER THE NUMBER OF VERTICES IN THE GRAPH \t::\t";
cin>>vertices;
}
void getdata()
{
cout<<"ADJANCY MATRIX ::"<<endl;
for(int i = 0 ; i < vertices ; i++)
{
for(int j = 0 ; j<vertices ; j++)
{
cout<<"CONNECTIVITY BETWEEN "<<arr[i]<<" and "<<arr[j]<<" :: ";
cin>>a[i][j];
}
}
}
void display()
{
cout<<"::::ADJANCY MATRIX::::"<<endl;
for(int i = 0 ; i < vertices ; i++)
{
for(int j = 0 ; j<vertices ; j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
}
void calllist()
{
node n[5];
for(int i = 0 ; i<vertices ; i++)
{
n[i].list(arr[i]);
}
for(int i = 0 ; i < vertices ; i++)
{
for(int j = 0 ; j<vertices ; j++)
{
if(a[i][j] == 1 && i!=j)
{
n[i].list(arr[j]);
}
}
}
for(int i = 0 ; i<vertices ; i++)
{
n[i].displaylist();
}
}
};
int main()
{
graph am;
am.getdata();
am.display();
am.calllist();
return 0;
}
Comments
Post a Comment