Implements Queue in C language

» Implements Queue in C language
C language is always very useful to implements data structure. This program will be highly helpful for the students and professional to use queue using C language.#include #include#define MAX 9void push(int queue[],int *front,int *rear,int item){if((*front==0 && *rear==MAX) || (*rear+1==*front)){printf(“nOver Flow…..”);return;}else if(*front==-1){*front=0;*rear=0;}else if(*rear==MAX){*rear=0;}else{*rear=*rear+1;}queue[*rear]=item;}int pop(int queue[],int *front,int *rear){int a;if(*front==-1){printf(“nUnder flow……”);return -1;}else{a=queue[*front];if(*front==MAX){*front=0;}else if(*front==*rear){*front=-1;*rear=-1;}else{*front=*front+1;}return a;}}void display(int queue[],int front,int rear){int i;if(front<=rear){for(i=front;i<=rear;i++){printf("nPosition: %dtVaue: %d",i,queue[i]);}}else{for(i=0;i<=rear;i++){printf("nPosition: %dtVaue: %d",i,queue[i]);}for(i=front;i<=MAX;i++){printf("nPosition: %dtVaue: %d",i,queue[i]);}}}int menu(){int c;printf("n1.Insertn2.Deleten3.Displayn4.Exit");printf("nEnter your choice: ");scanf("%d",&c);return c;}void main(){int queue[10];int front=-1,rear=-1;int c,item;while(1){c=menu();switch(c){case 1:printf("Enter item to insert: ");scanf("%d",&item);push(queue,&front,&rear,item);break;case 2:item=pop(queue,&front,&rear);if(item!=-1){printf("%d has been deleted...",item);}break;case 3:display(queue,front,rear);break;case 4:exit(0);default:printf("nWrong choice");}}}

Aly Chiman

Aly Chiman is a Blogger & Reporter at AlyChiTech.com which covers a wide variety of topics from local news from digital world fashion and beauty . AlyChiTech covers the top notch content from the around the world covering a wide variety of topics. Aly is currently studying BS Mass Communication at University.