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

#ADT Can anyone help me solve this question, I\'d be appreciate! #CProgramming A

ID: 3822239 • Letter: #

Question

#ADT Can anyone help me solve this question, I'd be appreciate! #CProgramming

A limited-sized Queue ADT is an abstract data type that has a limit on the length of the queue. It can be created with a static array of size N, where N is the maximum length of the array. In C, this structure can be defined as follows: typedef struct { int * data; // array of the data on the queue // you may add other attributes here but use as few as possible } queue_t; Write a pseudocode for the implementation of each of the following function prototypes (proper C code will also be accepted) void print (Q, x) - prints the entire queue Q from front to back. int enqueue (Q, x) - enqueues the element x into queue Q (if unsuccessful, return-1) *int dequeue (Q) - dequeues the next integer from front of the queue (if unsuccessful, return null) int isEmpty (Q) - returns 1 (true) or 0 (false) depending on emptiness of the queue Q unsigned int size (Q) - returns the number of items currently in the queue In your final solution, you may add any extra attributes that you feel is needed for this question but you must use as few extra attributes as possible.

Explanation / Answer

#include <stdio.h>

#include<conio.h>

#include <malloc.h>
#include <ctype.h>
#include <unistd.h>
struct linear_queue
{
int info;
struct linear_queue *next;
}*front,*rear,*newnode,*ptr;

void menu();
void display();
int enqueue(int);
int dequeue();
int isempty();
unsigned int asize();
int main()
{
//clrscr();
menu();
//getch();
return 0;
}

void menu()
{
int choice,item,sz;
printf("MENU");
printf(" 1. Insert into the queue");
printf(" 2. Delete from queue");
printf(" 3. Display");
printf(" 4. Size");
printf(" 5. Exit");
printf(" Enter your choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1:
//clrscr();
printf(" Enter the item tobe inserted: ");
scanf("%d",&item);
enqueue(item);
//clrscr();
printf(" After inserting queue is: ");
display();
//getch();
//clrscr();
menu();
break;
case 2:
//clrscr();
if(isempty()==1)
{
dequeue();
if(isempty()==1)
{
printf(" After deletion queue is: ");
display();
}
}
//getch();
//clrscr();
menu();
break;
case 3:
// clrscr();
if(isempty()==1)
{
printf("The queue is: ");
display();
}
//getch();
// clrscr();
menu();
break;
case 4:
  
sz=asize();
printf(" size is %d",sz);break;
case 5:
exit(1);
default:
//clrscr();
printf("Your choice is wrong ");
menu();
}
}

int isempty()
{
if((front==NULL)&&(rear==NULL))
{
printf(" Queue is empty");
return(0);
}
else
{
return(1);
}
}

int enqueue(int item)
{
newnode=(struct linear_queue*)malloc(sizeof(struct linear_queue));
newnode->info=item;
if((front==NULL)&&(rear==NULL))
{
front=newnode;
rear=newnode;
newnode->next=NULL;
}
else
{
rear->next=newnode;
newnode->next=NULL;
rear=newnode;
}

return 0;
}

int dequeue()
{
if(front==rear)
{
front=NULL;
rear=NULL;
}
else
{
front=front->next;
}

return 0;
}

void display()
{
int i;
ptr=front;
i=1;
while(ptr!=NULL)
{
printf(" Node %d : %d",i,ptr->info);
ptr=ptr->next;
i++;
}
}

unsigned int asize()
{int i;
ptr=front;
i=1;
while(ptr!=NULL)
{
printf(" Node %d : %d",i,ptr->info);
ptr=ptr->next;
i++;
}
return i-1;
}