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

1. Write a code segment using class queueClass that creates a queue of the integ

ID: 3534810 • Letter: 1

Question

1. Write a code segment using class queueClass that creates a queue of the integers 1-5.

2. Write a member function called Display that displays the elements of an object of type queueClass. Assume the pointer-based queue is in use, and note that you are writing a member function of the class, so you have access the private data members.

Explanation / Answer

#include #include #include struct Node { int Data; struct Node* next; }*rear, *front; void push(int value) { struct Node *temp; temp=(struct Node *)malloc(sizeof(struct Node)); temp->Data=value; if (front == NULL) { front=temp; front->next=NULL; rear=front; } else { front->next=temp; front=temp; front->next=NULL; } } void display() { struct Node *var=rear; if(var!=NULL) { printf(" Elements are as: "); while(var!=NULL) { printf(" %d",var->Data); var=var->next; } printf(" "); } else printf(" Queue is Empty"); } int main() { int i=0,j; front=NULL; printf(" 1. Push to Queue"); printf(" 2. Pop from Queue"); printf(" 3. Display Data of Queue"); printf(" 4. Exit "); while(1) { printf(" Choose Option: "); scanf("%d",&i); switch(i) { case 1: { int value; printf(" Enter a valueber to push into Queue: "); for(j=0;j