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");}}}

Read More Post

STAY CONNECTED

Most Popular

Why Serviced Apartments Are the Perfect Choice for Long-Term Stays in Singapore – Everything You Need to Know
17 Dec

Why Serviced Apartments Are the Perfect Choice for Long-Term Stays in Singapore – Everything You Need to Know

If you’re heading to Singapore for a few weeks or many months, maybe for work or study or just to

Manifesting Your Dream Career: Finding Your Passion And Purpose
01 Aug

Manifesting Your Dream Career: Finding Your Passion And Purpose

Are you passionate about finding your dream career? Manifesting can help you align your career with your passions and purpose.

Revolutionizing Your Ride: Expert Auto Service At Carolina Auto Service
27 Feb

Revolutionizing Your Ride: Expert Auto Service At Carolina Auto Service

Finding a reliable auto service provider is paramount in the bustling world of vehicle maintenance and repair. That's where Carolina

Floratam: The Robust Grass Solution From Council Growers SOD
25 Jan

Floratam: The Robust Grass Solution From Council Growers SOD

Floratam grass, a popular St. Augustine variety, has become a go-to choice for homeowners and landscapers seeking a lush, durable

Carolina Mobile Autoservice: Your Go-To For Expert Brake Service Repair
25 Jan

Carolina Mobile Autoservice: Your Go-To For Expert Brake Service Repair

For vehicle owners, the braking system is among the most critical components for safety and performance. Carolina Mobile Autoservice, a

Safeguarding Your Property: Expert Water Damage Services By MBC Capital
24 Jan

Safeguarding Your Property: Expert Water Damage Services By MBC Capital

Water damage can significantly impact homes and businesses, often leaving a trail of destruction and disruption in its wake. Understanding