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

___________________________________ Client.cpp Solution #ifndef LQUEUE #define L

ID: 3712600 • Letter: #

Question

___________________________________

Client.cpp

Explanation / Answer

#ifndef LQUEUE #define LQUEUE #include using namespace std; typedef int el_t; //create a struct that will have an operand, a operator, another operand struct node { el_t elem; node* next; }; class LQueue { // Data members private: node* front; // address to the front element node* rear; // address to the last element int count; // how many elements do we have right now? void queueError(string); // This displays an error messages passed to it and does exit(1); public: LQueue(); //Purpose to destroy //Parameters: nothing ~LQueue(); void addRear(el_t elem); // holds the function for adding an element to the queue //Purpose to delete elements from queue //Parameters: nothing el_t &deleteFront(); //Purpose to displays the content of the queue //Parameters: nothing bool isEmpty(); void displayAll(); // holds the function for showing all elements in the stack //Purpose to display the queue in reverse order }; #endif ________________________________ #include #include "lqueue.h" //PURPOSE: Constructor which initilizes front, rear, and count LQueue::LQueue() { front = NULL; rear = NULL; count = 0; } //PURPOSE: When the program hits and endbrace '}', delete the LQueue //ALGORITHM: While the LQueue isn't empty, delete front LQueue::~LQueue() { while (!isEmpty()) { deleteFront(); } } void LQueue::addRear(el_t value) { if (isEmpty()) { front = new node; rear = front; front->elem = value; front->next = NULL; count++; } else { rear->next = new node; rear = rear->next; rear->elem = value; rear->next = NULL; count++; } } //PURPOSE:To delete the front pointer and display the element //ALGORITHM:while the lqueue isn't empty, set a temp element to front->next // and deletethe front. Set the temp to the front and return the element el_t &LQueue::deleteFront() { if (isEmpty()) { queueError("UNABLE TO REMOVE FRONT. QUEUE UNDERFLOW."); int temp = 0; return temp; } else { node* second = front->next; int &sec = front->elem; delete front; front = second; count--; return sec; } } //PURPOSE: To return if a queue is empty or not (returns true or false) //ALGORITHM:if count is at the initilized state of 0, return true, else return false bool LQueue::isEmpty() { if (count == 0) return true; else return false; } //PURPOSE:To display all the elements in the lqueue //ALGORITHM: While the lqueue isn't empty, put a temp pointer to the front // and while the temp->next = NULL, keep displaying and moving // the element void LQueue::displayAll() { if (isEmpty()) { cout