/*Serial No.150 [swami132.cpp]*/
#include<stdio.h>
#include<conio.h>
#define maxsize 4
void enqueue(int *Q,int *f, int *r)
{
int ele;
if(*r>=maxsize-1)
{
printf("\nQueue is full. Value can't be added.");
return;
}
if(*f==-1)
{
(*f)++;
}
(*r)++;
printf("\nEntere the element to insert= ");
scanf("%d",&ele);
*(Q+*r)=ele;
}
void display(int *Q,int f,int r)
{
if(f==-1&&r==-1)
printf("\nQueue is empty.");
else
{
printf("\nElements in Queue are:\n");
for(int i=f;i<=r;i++)
{
printf("%d ",*(Q+i));
}
}
}
void dequeue(int *Q,int *f, int *r)
{
int ele;
if(*f==-1&&*r==-1)
{
printf("\nQueue is empty. Value can't be deleted.");
return;
}
else if(*f==*r)
{
ele=*(Q+*f);
*f=-1;
*r=-1;
}
else
{
ele=*(Q+*f);
(*f)++;
}
printf("\nDeleted Element= %d",ele);
}
void main()
{
int front1=-1,rear1=-1;
int queue1[maxsize];
int choice;
clrscr();
printf("\n\t[1] Enqueue");
printf("\n\t[2] Dequque");
printf("\n\t[3] Display");
printf("\n\t[7] Exit");
do
{
printf("\nEnter your choice= ");
scanf("%d",&choice);
switch(choice)
{
case 1: enqueue(queue1,&front1,&rear1);
break;
case 2: dequeue(queue1,&front1,&rear1);
break;
case 3: display(queue1,front1,rear1);
}
}while(choice!=7);
getch();
}
Thanz for this helpful blog
ReplyDelete