It configures storage (using arrays), queues where harder to manipulate then were stacks. It causes difficulties to handle full queues and empty queues. It is for queues that linked storage really comes into its own The linked implementation has two advantages over the array implementation (1) it is faster locations for insertion and deletion are same at the back and at the front and 2) it wastes no space Linked queues are just as easy to handle as are linked stacks. Program: Program to implement queue using linked list : # include<stdio.h> #include<conio.h> #include<stdio.h> struct node { int data; struct node *next; }; struct node *front=NULL ;*rear; void insertion() { int els; struct node *new node; new node=(struct node *)malloc(sizeof(struct node)); printf(“Enter data for new node: ”); scanf(“%d”,&ele); newnode
data=ele; newnode
next=NULL; if(front==NULL) { front=new node; rear=front; } else { rear
next= new code; rear= new node; } } void deletion() { struct node *temp; if(front==NULL) printf(“QUEUE underflow”); else { temp=front; front=front
next; printf(“Deleted element is : %d \n”, temp
data); free(temp); } } void display() { struct node *ptr; if(front===NULL) printf(“queue is empty”); else { printf(“elements of queue are :”); for(ptr=front; ptr!=NULL;ptr=ptr
next); printf(“%5d”,ptr
data); } } void main() { int ch; clrscr(); do { printf(“1. INSERTION \n”); printf(“2. DELETION \n”); printf(“3. DISPLAY \n”); printf(“4.EXIT \n”); printf(“Enter U r choice :”); scanf(“%d”,&ch); switch(ch) { case1: insertion(); break; case2: deletion(); break; case3: display(); break; case 4: exit(0); } } while(ch<=4) getch(); }
You liked the article?
Like: 0
Vote for difficulty
Current difficulty (Avg): Medium
TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.