Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with D in C++ please! infix2postfix.cpp #include stack.hpp using namespace std; // Auxiliary method, you probably find it useful // Operands are all

Need help with D in C++ please!

image text in transcribed

infix2postfix.cpp

#include "stack.hpp"

using namespace std;

// Auxiliary method, you probably find it useful // Operands are all lower case and upper case characters bool isOperand(char c){ return (c >= 'a' && c = 'A' && c

// Auxiliary method, you probably find it useful int precedence(char c) { if(c == '+' || c == '-'){ return 0; } if(c == '*' || c == '/'){ return 1; } if(c == '^'){ return 2; } return -1; }

int main(){ freopen("input_infix2postfix.txt", "r", stdin); string input; string solution; int line_counter = 0; while(cin >> solution){ cin >> input; Stack stack; string result;

//The input file is in the format "expected_solution infix_expression", //where expected_solution is the infix_expression in postfix format

for(int i=0; i

stack.hpp

//#include #include #include #include #include

// Ideally this would not be a huge number, you could also use a vector #define MAXSIZE 100000

using namespace std; template class Stack{ private: T arr[MAXSIZE]; // the actual stack int topIndex; // index of the top element public: Stack(){ topIndex = -1; // constructor }; ~Stack(){}; // destructor void push(T c); // push c to the list T pop(); // return and remove the top element in the stack T peek(); // return the top element in the stack int size(); // returns the size of the stack void display(); // display the stack in stdout };

input_infix2postfix.txt

ab+ a+b abcd^e-fgh*+^*+i- a+b*(c^d-e)^(f+g*h)-i ab+cd+* (a+b)*(c+d)

(b). (20points) Balancing parenthesis: Complete the balancing.cpp file based on the comments in the file. Specifically, complete the for loop as shown below to check whether s is balanced: 232425for(inti=0;i

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_2

Step: 3

blur-text-image_3

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

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

More Books

Students also viewed these Databases questions

Question

What are some standards of programming style and documentation?

Answered: 1 week ago