0% found this document useful (0 votes)
8 views2 pages

Blank

Uploaded by

dd7devdilip
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Blank

Uploaded by

dd7devdilip
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<stdio.

h>
#include<stdlib.h>
#de ne MAX 2

int queue[MAX];
int front=-1,rear=-1;

void insert(int num){


if (rear==MAX-1){
printf("queue is full\n");
return;
}
else if( front ==-1 && rear==-1){
front=rear=0;
}
else{
rear++;
}
queue[rear]=num;
}

void delete(){
if(front==-1||front>rear){
printf("queue is emptty\n");
}
else{
printf(" %d deleted from the queue\n",queue[front++]);
if(front>rear){
front=rear=-1;
}
}
}

void display(){
if(front==-1||front>rear){
printf("queue is emptty\n");
}
else{
printf("queue contents:\n");
for(int i=front;i<=rear;i++){
printf("%d\t\t",queue[i]);
}
}
}

int main(){
int choice,num;
while(1){
printf("enter 1 for insert\n");
printf("enter 2 for delete\n");
printf("enter 3 for display\n");
printf("enter 4 for exit\n");
printf("enter your choice:");
scanf("%d", &choice);
switch(choice){
case 1:
printf("enter the element to add:");
scanf("%d",&num);
insert(num);
break;
fi
case 2:
delete();
break;
case 3:
display();
break;
case 4:
printf("exiting.....\n");
exit(0);
default:
printf("please enter correcct choice\n") ;
}
}
return 0;
}

You might also like