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;jRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.