Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
#include<stdio.h>
//#include<alloc.h>
//void insert_vertex(int);
struct adj
int info;
};
struct node
int info;
adj *first;
};
void main()
{
int i;
clrscr();
scanf("%d",&i);
insert_vertex(i);
getch();
void insert_vertex(int i)
node *beg=NULL,*temp,*ptr;
int n;
for(n=1;n<=i;n++)
temp=(node *)malloc(sizeof(node));
temp->info=n;
temp->next=NULL;
temp->first=NULL;
if(beg==NULL)
beg=temp;
else
ptr=beg;
while(ptr->next!=NULL)
ptr=ptr->next;
ptr->next=temp;
insert_adj(beg);
int n;
char ch;
node *ptr=beg;
adj *p,*temp;
while(ptr!=NULL)
n=ptr->info;
fflush(stdin);
scanf("%c",&ch);
while(ch=='y'||ch=='Y')
temp=(adj *)malloc(sizeof(adj));
temp->next=NULL;
if(ptr->first==NULL)
ptr->first=temp;
else
p=ptr->first;
while(p->next!=NULL)
p=p->next;
p->next=temp;
fflush(stdin);
scanf("%c",&ch);
}//end of while
ptr=ptr->next;
}//end of while
traverse(beg);
}//end of insert_adg
node *ptr=beg;
adj *p;
printf("\n vertex\t adjacent nodes\n");
while(ptr!=NULL)
printf("\n %d\t",ptr->info);
p=ptr->first;
while(p!=NULL)
printf("%d\t",p->info);
p=p->next;
}//end of while
ptr=ptr->next;
}//end of while
}//end of fn traverse