// QUEUE
// Program 4 : To implement QUEUE using array

#include <stdio.h>
#include <conio.h>

#define MAX 20

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

 int insert(int );
 int delete();
void display();

main()
{
  int x,opn;

  do
  {
    printf("\n\n\t <1>INSERT    <2>DELETE    <3>DISPLAY    <4>EXIT");
    printf("\n\t Enter your option : ");
    scanf("%d",&opn);

    switch(opn)
	{
		case 1:
			printf("\t Enter number to insert : ");
			scanf("%d", &x);
			if( insert(x))
				printf("\n\t ERROR : OVERFLOW !!!");
			printf("\t Press any key to continue ...");
			getch();
			break;
		
		case 2:
			if( front == -1 || front>rear )
	       		printf("\t ERROR : UNDERFLOW !!!");
	      	else
	       		printf("\t deleted element is : %d", delete());
      		printf("\n\t Press any key to continue ...");
	      	getch();
	      	break;

      	case 3:
			if( front == -1 || front>rear )
				printf("\n\t QUEUE IS EMPTY");
			else
				display();
			printf("\n\t Press any key to continue ...");
			getch();
			break;
    }
  }while(opn!=4);
}
// end of main

int insert(int x)
{
  if(rear == MAX-1)
   return -1;

  if(front == -1)
   front = 0;

  rear++;
  queue[rear] = x;
  return 0;
}

int delete()
{
  if( front == -1 || front>rear )
   return -1;

  front++;
  return queue[front-1];
}

void display()
{
  int i;

  if( front == -1 || front>rear )
   return ;

  printf("\n\t QUEUE = [ ");
  for( i=front; i<=rear; i++)
   printf(" %d ",queue[i]);
  printf("]");
}



Output