#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
Recommended Answers
Jump to PostWhat's this?.. another guess what's wrong with my code game... huh
Not only do you want us to do the work for you, but you did not state how your program works, it's purpose or the desired output.
Jump to Post[boilerplate_help_info]
Posting requests for help must be well thought out if you want help quickly and correctly. Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful? Check your post with these checkpoints - what …
Jump to PostYou have to decide, is it egde or edge the name of your struct?
All 11 Replies
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.