#include<stdio.h>
#include<conio.h>
#define n 3
int front=-1,rear=-1;
int queue[n];
main()
{
void qinsert(int);
void qdelete();
void qdisplay();
int isfull();
int isempty();
int choice,item;
clrscr();
while(1)
{
printf("\n QUEUE PROGRAM \n");
printf("\n 1.insert");
printf("\n 2.delete");
printf("\n 3.display");
printf("\n 4.exit");
printf("\n enter your choice :");
scanf("%d",&choice);
switch(choice)
{
case 1:printf("enter the number to be inserted :");
scanf("%d",&item);
qinsert(item);
break;
case 2:qdelete();
break;
case 3:qdisplay();
break;
case 4:exit();
default:printf("\n invalid choice !!!");
}
}
}
void qinsert(int item)
{
if(isfull())
{
printf("\n overflow");
return;
}
if(front && rear==-1)
front=rear=0;
else
rear=rear+1;
queue[rear]=item;
if(rear==n-1)
printf("\n queue is full");
return;
}
void qdisplay()
{
int i;
if(isempty())
{
printf("\n no elements is the queue ");
return;
}
else
{
for(i=front;i<=rear;i++)
printf("\n%d",queue[i]);
}
return;
}
void qdelete()
{
int item;
if(isempty())
{
printf("\n underflow");
return;
}
else
item=queue[front];
printf("the elements deleted is %d ",item);
if(front==rear)
{
front=-1;
rear=-1;
}
else
front++;
return;
}
int isfull()
{
if(rear==n-1)
return 1;
else
return 0;
}
int isempty()
{
if(front==-1)
return 1;
else
return 0;
}
#include<conio.h>
#define n 3
int front=-1,rear=-1;
int queue[n];
main()
{
void qinsert(int);
void qdelete();
void qdisplay();
int isfull();
int isempty();
int choice,item;
clrscr();
while(1)
{
printf("\n QUEUE PROGRAM \n");
printf("\n 1.insert");
printf("\n 2.delete");
printf("\n 3.display");
printf("\n 4.exit");
printf("\n enter your choice :");
scanf("%d",&choice);
switch(choice)
{
case 1:printf("enter the number to be inserted :");
scanf("%d",&item);
qinsert(item);
break;
case 2:qdelete();
break;
case 3:qdisplay();
break;
case 4:exit();
default:printf("\n invalid choice !!!");
}
}
}
void qinsert(int item)
{
if(isfull())
{
printf("\n overflow");
return;
}
if(front && rear==-1)
front=rear=0;
else
rear=rear+1;
queue[rear]=item;
if(rear==n-1)
printf("\n queue is full");
return;
}
void qdisplay()
{
int i;
if(isempty())
{
printf("\n no elements is the queue ");
return;
}
else
{
for(i=front;i<=rear;i++)
printf("\n%d",queue[i]);
}
return;
}
void qdelete()
{
int item;
if(isempty())
{
printf("\n underflow");
return;
}
else
item=queue[front];
printf("the elements deleted is %d ",item);
if(front==rear)
{
front=-1;
rear=-1;
}
else
front++;
return;
}
int isfull()
{
if(rear==n-1)
return 1;
else
return 0;
}
int isempty()
{
if(front==-1)
return 1;
else
return 0;
}
No comments:
Post a Comment