Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please Write C code for the following guidelines... I\'m so lost! – Implementing

ID: 3676313 • Letter: P

Question

Please Write C code for the following guidelines... I'm so lost!

– Implementing a queue with an array?

Implement the following functions for manipulating a queue (without actually declaring the queue), based on an array of characters of size QUEUESZ, where QUEUESZ is a "const int" or a #include value, with a value of 20 (for now). The name of the queue is your choice. Pick a name. It will be declared in step B. A. Push - adds one element to the end of the queue (accepts a character as input), returns an int: a. i. -1 if the queue is already full, ii. 0 if the item was successfully added b. Pull - removes the front element (if it exists) and returns the value: NULL if there were no elements (queue was empty) The Front element itself, if there was one i. ii. c. Front - does NOT remove anything. Returns the value: i. ii. NULL if there are no elements (queue is empty) The front char element if there is one d. isFull- does NOT remove anything. Returns an int: i. ii. iii. 0 if there are no elements (the queue is empty) 1 if the queue is full -1 for all other cases B. Using the above functions, write a program that: a. Declares the queue with a size of QUEUESZ characters b. Uses your functions above to do the following: i. Accept input characters, 1 at a time until the symbol A is input ii. Push each character onto the queue ii. Output the queue (front to end) after all inputs have been received Notes: Your main program should have NO access to the queue except through the above functions The queue array & value of the index to the front and end ARE global, so all your functions can get at them, but the main code must never look at or use them If the queue is full and more data keeps coming, your program should ignore the data and reply, 1. 2. "The queue is full. Enter the 'n' character to stop.". 3. Repeat the above message if more input (other than "A" keeps coming)

Explanation / Answer

#include<stdio.h>
#include<conio.h>
#define QUEUESZ 20
char queue[QUEUESZ];
int front=-1,rear=-1;
void frontele();
int push();
char pull();
int is_full();
void display_queue();


int main()
{
char option;
do
{
printf(" 1.Insert ");
printf(" 2.Delete ");
printf(" 3.Display");
printf(" 4.front");
printf(" 5.is_full");
printf(" 6.exit");
printf(" Enter your choice:");
scanf(" %c",&option);
switch(option)
{
case '1': printf("%d",push());
display_queue();
break;
case '2': printf("%c",pull());
break;
case '3': display_queue();
break;
case '4': frontele();
break;   
case '5': printf("%d",is_full());
break;
case '^': return 0;
}

}while(option!='^');
}
int is_full()
{
if(front==0 && rear==QUEUESZ-1)
return 1;
else if(front==-1)
return 0;
else
return -1;

}
void frontele()
{
if(front==-1)
printf("null");
else
printf("%c",queue[front]);

}
int push()
{
char ele;
printf("Enter the element");
scanf(" %c",&ele);
if(front==0 && rear==QUEUESZ-1)
{
printf("queue is full please exit");
return -1;
}
else if(front==-1&&rear==-1)
{
front=rear=0;
queue[rear]=ele;
return 0;

}
else if(rear==QUEUESZ-1 && front!=0)
{
rear=0;
queue[rear]=ele;
return 0;
}
else
{
rear++;
queue[rear]=ele;
return 0;
}
}
char pull()
{
int element;
if(front==-1)
{
return '0';
}
element=queue[front];
if(front==rear)
{
front=rear=-1;
}
else
{
if(front==QUEUESZ-1)
front=0;
else
front++;
return element;
}

}
void display_queue()
{
int i;
if(front==-1)
printf(" No elements to display");
else
{
printf(" The queue elements are: ");
for(i=front;i<=rear;i++)
{
printf(" %c",queue[i]);
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote