Friday, June 24, 2011

ARRAY IMPLEMENTATION OF QUEUE

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

int q[50],frnt,rear,choice;

void view();
void enqueue();
void dequeue();

void main()
{
frnt=-1;

rear=-1;
clrscr();
printf("\n\n\t\tPROGRAM TO IMPLEMENT QUEUE AS ARRAY\n");
do
{
 printf("\nenter your choice\n\n1.view\n2.enqueue\n3.dequeue\n4.exit");
 scanf("%d",&choice);
  switch(choice)
  {
   case 1:view();
      break;
   case 2:enqueue();
      break;
   case 3:dequeue();
      break;
   case 4:printf("\n\nTHANKYOU");
      getch();
      default:printf("\n\nINVALID CHOICE\n");
  }
}while(choice!=4);
}

void view()
{
int c;
c=frnt;
printf("\nFRONT-->");
do
{
printf("%d-",q[c]);
c++;
}while(c<rear);
printf("<--REAR");
getch();
}

void enqueue()
{
int data;
printf("\nenter the elemente to be inserted \n");
scanf("%d",&data);
if(rear<50)
{
rear++;
q[rear]=data;
view();
}
else
printf("\nQUEUE IS FULL");
}

void dequeue()
{
printf("\nthe data being deleted is %d",q[frnt]);
q[frnt]=0;
frnt++;
view();
}

No comments:

Post a Comment