Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#define SIZE 5 #define NULL _ VALUE 0 void next ( int * pointer ) ; void enqueue ( ) ; void dequeue ( )

#define SIZE 5
#define NULL_VALUE 0
void next(int *pointer);
void enqueue();
void dequeue();
void print_queue();
int buffer[SIZE];
int head;
int tail;
int main(void)
{
int menu;
while (1)
{
printf("Select a number (1. Enqueue 2. Dequeue 3. Queue Print 4. Exit): ");
scanf("%d", &menu);
if (menu ==1)
enqueue();
else if (menu ==2)
dequeue();
else if (menu ==3)
print_queue();
else if (menu ==4)
break;
}
return 0;
}
void next(int *pointer)
{
if (*pointer != SIZE -1)
*pointer =*pointer +1;
else
*pointer = NULL_VALUE;
}
void enqueue()
{
int data;
printf("Enqueue a number: ");
scanf("%d", &data);
if (NULL_VALUE != buffer[head])
{
printf("Queue is full
");
return;
}
buffer[head]= data;
next(&head);
}
void dequeue()
{
int data = buffer[tail];
if (NULL_VALUE == data)
{
printf("Queue is empty
");
return;
}
printf("Dequeued number: %d
", data);
buffer[tail]= NULL_VALUE;
next(&tail);
}
void print_queue()
{
int i;
printf("Queue is: ");
for (i =0; i < SIZE; i++)
printf("%d ", buffer[i]);
printf("\tHead: %d\tTail: %d
", head, tail);
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

More Books

Students also viewed these Databases questions

Question

Would giving rewards or administering punishments be

Answered: 1 week ago

Question

6. What actions might make employers lose elections?

Answered: 1 week ago