/* Program of queue using linked list*/ # include # - TopicsExpress



          

/* Program of queue using linked list*/ # include # include struct node { int info; struct node *link; }*front=NULL,*rear=NULL; main() { int choice; while(1) { printf("1.Insert "); printf("2.Delete "); printf("3.Display "); printf("4.Quit "); printf("Enter your choice : "); scanf("%d", &choice); switch(choice) { case 1: insert(); break; case 2: del(); break; case 3: display(); break; case 4: exit(1); default : printf("Wrong choice "); }/*End of switch*/ }/*End of while*/ }/*End of main()*/ insert() { struct node *tmp; int added_item; tmp = (struct node *)malloc(sizeof(struct node)); printf("Input the element for adding in queue : "); scanf("%d",&added_item); tmp->info = added_item; tmp->link=NULL; if(front==NULL) /*If Queue is empty*/ front=tmp; else rear->link=tmp; rear=tmp; }/*End of insert()*/ del() { struct node *tmp; if(front == NULL) printf("Queue Underflow "); else { tmp=front; printf("Deleted element is %d ",tmp->info); front=front->link; free(tmp); } }/*End of del()*/ display() { struct node *ptr; ptr = front; if(front == NULL) printf("Queue is empty "); else { printf("Queue elements : "); while(ptr != NULL) { printf("%d ",ptr->info); ptr = ptr->link; } printf(" "); }/*End of else*/ }/*End of display()*/
Posted on: Sun, 14 Jul 2013 07:05:47 +0000

Trending Topics



Recently Viewed Topics




© 2015