int main(){ struct node* head = NULL; struct node* second = NULL; struct node* third = NULL; struct node* newnode = NULL; int key, ch, ch1; head = (struct node*)malloc(sizeof(struct node)); second = (struct node*)malloc(sizeof(struct node)); third = (struct node*)malloc(sizeof(struct node)); head->data = 4; head->next = second; second->data = 5 ; second->next = third; third->data = 6; third->next = NULL; printf("\nOriginal List::\t\t"); printList(head); ch1 = 0; while(ch1 == 0){ printf("\nEnter choice::\n1.Insertion 2.Deletion 3. Exit::"); scanf("%d",&ch); switch(ch){ case 1: printf("\nEnter key for Insertion::\t"); scanf("%d", &key); printf("\nInsertion in beg::\t"); insertBeg(&head,key); printList(head); continue; case 2: printf("\nEnter key for Deletion::\t"); scanf("%d", &key); printf("\nAfter Deletion::\t"); deleteKey(&head,key); printList(head); continue; case 3: ch1 = 1; } } getchar(); return 0; }
void minimumSpanningTreePrim(struct gnode *adj[],int num){ typedef enum { UNSEEN, INTREE, NEAR } stat; int parent[MAX],status[MAX]={UNSEEN}, nearWt[MAX]; int stuck, current, edgeCount, minWt, ver, wt, w; struct gnode *ptr, *nearList, *ptr2; current=0; stuck=0; status[current]=INTREE; edgeCount=0; while((edgeCount<=num-1)&&!stuck){ ptr=adj[current]; while(ptr!=NULL){ ver=ptr->vertex; wt=ptr->weight; if((status[ver]==NEAR) && (wt<nearWt[ver])){ parent[ver]=current; nearWt[ver]=wt; } else if(status[ver]==UNSEEN){ status[ver]=NEAR; parent[ver]=current; insertBeg(nearList,ver); } ptr=ptr->next; } if(nearList==NULL){ stuck=1; //true; } else{ current=nearList->vertex; minWt=nearWt[current]; ptr2=nearList->next; while(ptr2!=NULL){ w=ptr2->vertex; if(nearWt[w]<minWt){ current=w; minWt=nearWt[w]; } ptr2=ptr2->next; } //deletelist(); //TODO deleteFromList(nearList,current); status[current]=INTREE; edgeCount+=1; } } for(current=1;current<num;current++){ printf("(%d,%d)",current,parent[current]); } }