Question: 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

1 Expert Approved Answer
Step: 1 Unlock

Question Write function infixToPostfix for infix to postfix conversion c include linkedStackh void i... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!