void edges() { int h,x,y; printf("enter number of edges..."); scanf("%d",&ne); for(h=0;h<ne;h++) { printf("\nenter starting & ending vertices of %d edge..",h+1); scanf("%d %d",&x,&y); { int t,u; if(!search(x,first,nv)) { printf("enter valid vertices.."); h--; continue; } for(t=0;(first+t)->x!=x;t++); if(!search(y,first,nv)) { printf("enter valid vertices.."); h--; continue; } for(u=0;(first+u)->x!=y;u++); insend(y,first+t); insend(x,first+u); } } }
void bfs() { struct neel *p; neel:if(!getnext(&p)) return; if(ifexist(p->x,u)) goto neel; printf("%d ",p->x); u=insend(p->x,u); p=p->y; for(;p!=NULL;) { s=insend(p->x,s); p=p->y; } p=NULL; bfs(); }
void main() { vertices(); edges(); s=insend(first->x,s); printf("\nBreadth First Search Sequence :- "); bfs(); getch(); }
void insert(nodeptr list, int n) { int i=1; char x; for(i=1;i<=n;i++) { printf("Enter the item to be inserted at node %d ",i); x=getche(); printf("\n"); if(i==1) insbgn(&list,x); else if(i==n) insend(&list,x); else { nodeptr p,q; p=list; q->next=p; insafter(q,x); } } printf("Nodes inserted with the given info\n"); }