#include <stdio.h>
#include <conio.h>
#define max 3
void main()
{
int queue[max],data;
int front,rear,reply,option;
clrscr();
//... init queue
front = rear = 0;
do
{
printf("\n 1. insert queue");
printf("\n 2. delete queue");
printf("\n 3. exit");
printf("\nSelect proper option :");
scanf("%d",&option);
switch(option)
{
case 1 ://insert
printf("\nEnter data : ");
scanf("%d",&data);
reply = insertq(queue,&front,&rear,&data);
if ( reply == - 1)
printf("Que is full");
else
printf("Inserted data in queue");
break;
case 2 : //dele
reply = delq(queue,&front,&rear,&data);
if ( reply == -1 )
printf("Queue is empty ");
else
printf("Deleted data is : %d", data);
break;
case 3 : exit(0);
} //switch
} while(1);
} // main
int insertq ( int queue[max], int *front, int *rear , int *data)
{
if ( (*rear + 1 ) % max == *front)
return(-1);
else
{
*rear = (*rear + 1) % max;
queue[*rear] = *data;
return(1);
} // else
} // insert
int delq( int queue[max], int *front, int *rear , int *data)
{
if ( *front == *rear)
return(-1);
else
{
*front = (*front + 1 ) % max;
*data = queue[*front];
return(1);
} // else
} // insert
0 Comments