C Program For Queue Using Array

/*Queue using array*/
#include<stdio.h>
#include<conio.h>
#define MAX_SIZE 10
int top=-1;
int bot=0;

void enque(int[]);
void deque(int[]);
void display(int[]);
void isempty(void);
void isfull(void);

void main(void)
  {
int a[MAX_SIZE],ch;
clrscr();
do
{
printf("\n1.Enque\n");
printf("2.Dque\n");
printf("3.Display\n");
printf("4.Isempty\n");
printf("5.Isfull\n");
printf("6.Exit\n");
printf("Enter the choice");
scanf("%d",&ch);
 switch(ch)
 {
 case 1:enque(a);
  break;
 case 2:deque(a);
  break;
 case 3:display(a);
  break;
 case 4:isempty();
  break;
 case 5:isfull();
  break;
 }
}while(ch!=6);
}


void enque(int x[MAX_SIZE])
{
 if (top<MAX_SIZE-1)
 {
 top++;
 printf("Enter the element\n");
 scanf("%d",&x[top]);
 }
 else
 {
 isfull();
 }
}

void deque(int x[MAX_SIZE])
{
 if (top>=bot)
 {
 printf("The element to be deleted is %d\n",x[bot]);
 bot++;
 }
 else
 {
 isempty();
 }
}




void display(int x[MAX_SIZE])
{
int i;
 for(i=bot;i<=top;i++)
 {
 printf("%d ",x[i]);
 }

}


void isempty(void)
{
 if(top<bot)
 {
 printf("Q is empty\n");
 }
 else
 {
 printf("Q is not empty\n");
 }
}


void isfull(void)
{
 if (top==MAX_SIZE-1)
 {
 printf("Q is full\n");
 }
 else
 {
 printf("Q is not full\n");
 }
}
Bhanu Namikaze

Bhanu Namikaze is an Ethical Hacker, Web Developer, Student and Mechanical Engineer. He Enjoys writing articles, Blogging, Solving Errors and Social Networking. Feel Free to let me know any of your concerns about hacking or let me know if you need any more methods on hacking anything. Enjoy Learning

No comments:

Post a Comment