#include<stdio.h>
#include<conio.h>
struct egde
{
int nodeno;
struct edge*next;
};
struct node
{
int nodeno;
struct node *next;
struct edge *link;
};
struct node*graph=NULL;
typedef struct node node;
typedef struct egde edge;
node*find(int);
void insert_egde();
void insert_node();
void display();
int main()
{
int ch,i,j;
do{
printf("\ninsert node");
printf("\ninsert edge");
printf("\ndisplay");
printf("\nexit");
printf("\nenter choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
insert_node();
break;
case 2:
insert_egde();
break;
case 3:
display();
break;
case 4:
exit(0);
break;
}
}while(ch!=5);
}
void insert_node()
{
int inf;
node*new1;
node*loc;
printf("enter info:");
scanf("%d",&inf);
new1=(node*)malloc(sizeof(node));
new1->nodeno=inf;
new1->link=NULL;
new1->next=NULL;
if(graph==NULL)
graph=new1;
else
{
loc=find(inf);
if(loc!=NULL)
printf("node present");
else
{
new1->next=graph;
graph=new1;
}
}
}
node* find(int inf)
{
node*temp=graph;
if(temp->nodeno==inf)
return graph;
else
{
while(temp!=NULL)
{
if(temp->nodeno==inf)
return temp;
}
return temp;
}
}
void insert_egde()
{
int src,dest;
node *loc1,*loc2;
printf("enter source:");
scanf("%d",&src);
printf("enter dest:");
scanf("%d",&dest);
loc1=find(src);
loc2=find(dest);
if(loc1==NULL || loc2==NULL)
printf("egde not possible!");
else
{
edge*new1;
new1=(edge*)malloc(sizeof(edge));
new1->next=loc1->link;
new1->nodeno=dest;
loc1->link=new1;
}
}
void display()
{
node *temp1=graph;
edge *temp2;
while(temp1!=NULL)
{
temp2=temp1->link;
printf("%d ",temp1->nodeno);
while(temp2!=NULL)
{
printf("%d,",temp2->nodeno);
}
printf("\n");
}
}
gourav1 -12 Posting Whiz in Training
zeroliken 79 Nearly a Posting Virtuoso
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
sharathg.satya -10 Posting Whiz in Training
gourav1 -12 Posting Whiz in Training
sharathg.satya -10 Posting Whiz in Training
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
mikrosfoititis 0 Junior Poster in Training
gourav1 -12 Posting Whiz in Training
sharathg.satya -10 Posting Whiz in Training
gourav1 -12 Posting Whiz in Training
mikrosfoititis 0 Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.