Skip to content

Commit ce25ce3

Browse files
Add files via upload
1 parent bfd5e87 commit ce25ce3

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#include<stdio.h>
2+
#include<stdlib.h>
3+
typedef struct node_list
4+
{
5+
int data;
6+
struct edge_list*edge;
7+
}nl;
8+
typedef struct edge_list
9+
{
10+
struct node_list*node;
11+
struct edge_list*next;
12+
}el;
13+
void connect(nl **arr)
14+
{
15+
int a,b,i=0,j=0;
16+
printf("Enter the node you want to connect : ");
17+
scanf("%d",&a);
18+
printf("Enter the node to which you want to connect the node : ");
19+
scanf("%d",&b);
20+
while(arr[i]->data!=a)
21+
{
22+
i++;
23+
}
24+
while(arr[j]->data!=b)
25+
{
26+
j++;
27+
}
28+
el*temp=(el*)malloc(sizeof(el));
29+
el*ptr=arr[i]->edge;
30+
if(ptr==NULL)
31+
{
32+
ptr=temp;
33+
arr[i]->edge=ptr;
34+
}
35+
else
36+
{
37+
while(ptr->next!=NULL)
38+
{
39+
ptr=ptr->next;
40+
}
41+
ptr->next=temp;
42+
}
43+
temp->next=NULL;
44+
temp->node=arr[j];
45+
}
46+
void display(nl **arr,int n)
47+
{
48+
for(int i=0;i<n;i++)
49+
{
50+
printf("%d\t\t",arr[i]->data);
51+
el*p=arr[i]->edge;
52+
while(p!=NULL)
53+
{
54+
printf("%d , ",p->node->data);
55+
p=p->next;
56+
}
57+
printf("\n");
58+
}
59+
}
60+
int main()
61+
{
62+
nl*arr[100];
63+
int n,c;
64+
printf("Enter the no. of nodes in your graph : ");
65+
scanf("%d",&n);
66+
for(int i=0;i<n;i++)
67+
{
68+
arr[i]=(nl*)malloc(sizeof(nl));
69+
printf("Enter the data to be stored in node %d : ",i+1);
70+
scanf("%d",&arr[i]->data);
71+
arr[i]->edge=NULL;
72+
}
73+
printf("Do you want to make connections : 1-YES\n0-NO\nEnter your choice : ");
74+
scanf("%d",&c);
75+
while(c)
76+
{
77+
connect(arr);
78+
printf("Do you want to make connections : 1-YES\n0-NO\nEnter your choice : ");
79+
scanf("%d",&c);
80+
}
81+
display(arr,n);
82+
}

0 commit comments

Comments
 (0)