Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write function infixToPostfix() for infix to postfix conversion c++; #include linkedStack.h void infixToPostfix(string str){ /* CODE HERE */ } int main(){ string str = 3+4*5;

Write function infixToPostfix() for infix to postfix conversion c++;

#include "linkedStack.h"

void infixToPostfix(string str){

/* CODE HERE */

}

int main(){

string str = "3+4*5";

cout << str << endl;

infixToPostfix(str);

cout << endl;

str = "(5+4)*(3+3)";

cout << str << endl;

infixToPostfix(str);

cout << endl;

str = "(A+B)*C-(D-E)*(F+G)";

cout << str << endl;

infixToPostfix(str);

cout << endl;

return 0;

}

******linkedStack.h*********

#include

using namespace std;

class Node {

public:

char data;

Node *link;

};

class myException : public runtime_error {

public:

myException(string const& msg) : runtime_error(msg){}

};

class linkedStack {

private:

Node *head; //pointer to the stack

public:

linkedStack(){

head = NULL;

}

~linkedStack(){

reset();

}

bool isEmpty(){

return head == NULL;

}

char top(){

if(isEmpty()){

throw myException("Stack underflow");

}

return head->data;

}

void print(){

Node *current = head;

if(isEmpty()){

cout << "";

}

else{

while(current != NULL){

cout << current->data << " ";

current = current->link;

}

}

cout << endl;

}

void push(char value){

Node *newNode = new Node;

newNode->data =value;

newNode->link =head;

head = newNode;

}

char pop(){

if(head == NULL){

cout << "Empty Stack."<

return 0;

}

char value = head->data;

Node *popNode = head;

head = head->link;

delete popNode;

return value;

}

void reset(){

Node *resetNode = head;

while(head != NULL){

head = head->link;

delete resetNode;

resetNode = head;

}

}

};

Im not sure how the function infixToPostfix() could be implemented for this excercice.

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

Guide To Client Server Databases

Authors: Joe Salemi

2nd Edition

1562763105, 978-1562763107

More Books

Students also viewed these Databases questions