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

i solved it but wrong , need help Consider the linked-structure based Queue ADT

ID: 3849153 • Letter: I

Question

i solved it but wrong ,

need help

Consider the linked-structure based Queue ADT hereafter. struct NodeType {ItemType info: NodeType* next;} class QueueType {private: NodeType*qFront qRear public: QueueType(): ~QueueType(): bool IsEmpty(): void Enqueue(ItemType item): void Dequeue (ItemType& item): }: (a) Code the destructor, using public member functions only. QueueType:: ~QueueType() { (b) Complete the code below, without using any member function. QueueType:: ~QueueType() { NodeType*tmp: while (

Explanation / Answer

QueueType::~QueueType() {
   NodeType *node;
   ItemType item; //wwe cannot delete item, stack variable
   while(!isEmpty()) {
       node = qFront; //node should be deleted
       dequeue(item);
       delete node;
   }
}

QueueType::~QueueType() {
   while (qFront != NULL) {
       NodeType *tmp = qFront;
       qFront = qFront.next;
       delete tmp;
   }
   qRear = NULL; //though not required
}

NOTE: You cannot delete itemtype because we are not using pointer/heap alocation fot ItemType.

I hope this will help you. Let me know if you need any guidance. I shall try my best to resolve all issues in this programming.