0% found this document useful (0 votes)
17 views4 pages

static implementation of queue

data structure computer science bca
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views4 pages

static implementation of queue

data structure computer science bca
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

/* static implementation of queue */

# include<stdio.h>

#define max 5

struct queue

int data[max];

int front,rear;

};

void intTQ(struct queue *q)

q->front = q->rear =-1;

int isEmptyQ(struct queue *q)

if(q->front == q->rear)

return 1;

else

return 0;

int isFullQ(struct queue *q)

if(q->rear == max - 1)

return 1;

else

return 0;

void insertQ(struct queue *q,int x)

q->data[++(q->rear)] =x;

int deleteQ(struct queue *q)


{

return (q-> data[++(q-> front)]);

void display(struct queue *q)

int i;

printf("\nQueue contents are:\t");

for(i=q-> front+1;i<=q->rear;i++)

printf("%d\t",q-> data[i]);

/* main program */

void main()

struct queue q1;

int ch,x;

clrscr();

intTQ(&q1);

do

printf("\n1-insert\n2-delete\n3-exit\n");

printf("enter your choice\n");

scanf("%d",&ch);

switch(ch)

case 1: if(isFullQ(&q1))

printf("queue is full\n");

else

printf("enter element to be insert\n");

scanf("%d",&x);

insertQ(&q1,x);
display(&q1);

break;

case 2: if(isEmptyQ(&q1))

printf("queue is empty\n");

else

printf("deleted element is %d\n",deleteQ(&q1));

display(&q1);

break;

case 3:

exit(0);

break;

}while(ch>0 && ch<3);

}
output:-

You might also like