Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I would like some help in creating and implementing two functions into my code, the two functions are shuntingYard() and postfix(). This is what

Hello, I would like some help in creating and implementing two functions into my code, the two functions are shuntingYard() and postfix().

image text in transcribed

image text in transcribed

This is what I have so far:

queueADT.h

#ifndef QUEUEADT_H #define QUEUEADT_H

template class queueADT{ public: virtual bool isEmptyQueue() const = 0; //function to see if queue is empty virtual bool isFullQueue() const = 0; //function to see if queue is full virtual void initializeQueue() = 0; //function to make queue empty virtual Type front() const = 0; //function to return first element of queue virtual Type back() const = 0; //function to return last element of queue virtual void addQueue(const Type& queueElement) = 0; //function to add queueElement to queue virtual void deleteQueue() = 0; //function to remove the first element of queue };

#endif /* QUEUEADT_H */

-----------------------------------

stackADT.h

#ifndef STACKADT_H #define STACKADT_H

template class stackADT{ public: virtual void initializeStack() = 0; //to initialize stack to an empty stack virtual bool isEmptyStack() const = 0; //function to see if stack is empty virtual bool isFullStack() const = 0; //function to see if stack is full virtual void push(const Type& newItem) = 0; //function to add newItem to stack virtual Type top() const = 0; //function to return the top element of stack virtual void pop() = 0; //function to remove the top element of stack };

#endif /* STACKADT_H */

----------------------------------------

linkedStack.h

#ifndef LINKEDSTACK_H #define LINKEDSTACK_H

#include #include #include "stackADT.h" using namespace std;

template class nodeType{ Type info; nodeType *next; };

template class linkedStackType: public stackADT{ public: const linkedLStackType& operator= (const linkedStackType&); //overload assignment operator bool isEmptyStack() const; //to see if stack is empty bool isFullStack() const; //to see if stack is full void initializeStack(); //function to initialize stack to empty void push(const Type& newItem); //add newItem to stack Type top() const; //return top element of stack void pop(); //remove top element of stack linkedStackType(); //default constructor linkedStackType(const linkedStackType& otherStack); //copy constructor ~linkedStackType(); //destructor private: nodeType *stackTop; //pointer to the stack void copyStack(const linkedStackType& otherStack); //function to make a copy of otherStack };

//default constructor template linkedStackType::linkedStackType(){ stackTop = nullptr; }

template bool linkedStackType::isEmptyStack() const{ return(stackTop == nullptr); }//end isEmptyStack

template bool linkedStackType::isFullStack() const{ return false; }//end isFullStack

template void linkedStackType::initializeStack(){ nodeType *temp; //pointer to delete the node while(stackTop != nullptr){ //while the stack is not empty temp = stackTop; //set temp to point to current node stackTop = stackTop->next; //move stackTop to next node delete temp; }//end while }//end initializeStack

template void linkedStackType::push(const Type& newElement){ nodeType *newNode; //pointer to create new node newNode = new nodeType; //create node newNode->info = newElement; //store newElement in node newNode->next = stackTop;//insert newNode before stackTop stackTop = newNode; //set stackTop to point to top node }//end push

template Type linkedStackType::top() const{ assert(stackTop != nullptr){ //if stack is empty return stackTop->info; } }//end top

template void linkedStackType::pop(){ nodeType *temp; if(stackTop != nullptr){ temp = stackTop; stackTop = stackTop->next; delete temp; } else{ cout

template void linkedStackType::copyStack (const linkedStackType& otherStack){ nodeType *newNode, *current, *last; if(stackTop != nullptr){ //if stack is not empty, make it empty initializeStack(); } if(otherStack.stackTop == nullptr){ stackTop = nullptr; } else{ current = otherStack.stackTop; //set current to point to stack //to be copied //copy the stackTop element of stack stackTop = new nodeType; //create the node stackTop->info = current->info; //copy info stackTop->next = nullptr; //set next to nullptr last = stackTop; //set last to point to the node current = current->next; //set current to point to next node //copy remaining stack while(current != nullptr){ newNode = new nodeType; newNode->info = current->info; newNode->next = nullptr; last->next = newNode; last = newNode; current = current->next; }//end while }//end else }//end copyStack

//copy constructor template linkedStackType::linkedStackType( const linkedStackType& otherStack){ stackTop = nullptr; copySack(otherStack); }//end copy constructor

//destructor template linkedStackType::~linkedStackType(){ initializeStack(); }//end destructor

//overloading assignment operator template const linkedStackType &linkedStackType::operator= (const linkedStackType& otherStack){ if(this != &otherStack){ //avoid self-copy copyStack(otherStack); } return *this; }//end operator =

#endif /* LINKEDSTACK_H */

----------------------------------------

linkedQueue.h

#ifndef LINKEDQUEUE_H #define LINKEDQUEUE_H

#include #include #include "queueADT.h" using namespace std;

//definition of the node template class nodeType{ Type info; nodeType *next; };

template class linkedQueueType: public queueADT{ public: const linkedQueueType& operator= (const linkedQueueType&); //overload the assignment operator bool isEmptyQueue() const; //fucntion to see if queue is empty bool isFullQueue() const; //function to see if queue is full void initializeQueue(); //function to make queue empty Type front() const; //function to return the first element of queue Type back() const; //function to return the last element of queue void addQueue(const Type& queueElement); //function to add queueElement to queue void deleteQueue(); //function to remove the first element of queue linkedQueueType(); //default constructor linkedQueueType(const linkedQueueType& otherQueue); //copy constructor ~linkedQueueType(); //destructor private: nodeType *queueFront; //pointer to front of queue nodeType *queueRear; //pointer to rear of queue };

//default constructor template linkedQueueType::linkedQueueType(){ this->queueFront = nullptr; //set front to nullptr this->queueRear = nullptr; //ser rear to nullptr }//end default constructor

template bool linkedQueueType::isEmptyQueue() const{ return (this->queueFront == nullptr); }//end isEmptyQueue

template bool linkedQueueType::isFullQueue() const{ return false; }//end isFullQueue

template void linkedQueueType::initializeQueue(){ nodeType *temp; while(this->queueFront != nullptr){ //while there are elements in queue temp = this->queueFront; //set temp to point to current node this->queueFront = this->queueFront->next; // advance first node to next one delete temp; } this->queueRear = nullptr; //set rear to nullptr }//end initializeQueue

template void linkedQueueType::addQueue(const Type& newElement){ nodeType *newNode; newNode = new nodeType; newNode->info = newElement; newNode->next = nullptr; if(this->queueFront == nullptr){ //if queue is empty this->queueFront = newNode; this->queueRear = newNode; } else{ //add newNode at the end this->queueRear->next = newNode; this->queueRear = this->queueRear->next; } }//end addQueue

template Type linkedQueueType::front() const{ assert(this->queueFront != nullptr); return this->queueFront->info; }//end front

template Type linkedQueueType::back() const{ assert(this->queueRear != nullptr); return this->queueRear->info; }//end back

template void linkedQueueType::deleteQueue(){ nodeType *temp; if(!isEmptyQueue()){ temp = this->queueFront; //make temp point to first node this->queueFront = this->queueFront->next; //advance queueFront delete temp; //delete first node if(this->queueFront == nullptr){ //if after deleting the queue //the queue becomes empty this->queueRear = nullptr; //set queueRear to nullptr } }//end if else{ cout

//destructor template linkedQueueType::~linkedQueueType(){ initializeQueue(); }//end destructor

template const linkedQueueType& linkedQueueType::operator= (const linkedQueueType& otherQueue){ if(this != &otherQueue){ //avoid self-copy linkedQueueType(otherQueue); } return *this; }//end assignment operator

//copy constructor template linkedQueueType::linkedQueueType (const linkedQueueType& otherQueue){ nodeType *newNode, *current, *last; if(this->queueFront != nullptr){ //if queue is not empty, make it empty initializeQueue(); } if(otherQueue.this->queueFront == nullptr){ this->queueFront = nullptr; } else{ current = otherQueue.this->queueFront; //set current to point to queue //to be copied //copy the first element of queue this->queueFront = new nodeType; //create the node this->queueFront->info = current->info; //copy info this->queueFront->next = nullptr; //set next to nullptr last = this->queueRear; //set last to point to the node current = current->next; //set current to point to next node //copy remaining stack while(current != nullptr){ newNode = new nodeType; newNode->info = current->info; newNode->next = nullptr; last->next = newNode; last = newNode; current = current->next; }//end while }//end else }

#endif /* LINKEDQUEUE_H */

Write a program that prompts the user to input an infix expression, such as and converts the output to postfix notation. The corresponding output in this case will be 512+4*3- Likewise, the expression 3+4 *2/(1-5) A 23 where A represents the power operator, results in postfix notation: 342 15-23AA+

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

0132742926, 978-0132742924

More Books

Students also viewed these Databases questions