Question
With use this stack class please implement InfixToPostfix function in the given stack header as a public function( give information about infix to postfix notation
With use this stack class please implement InfixToPostfix function in the given stack header as a public function( give information about infix to postfix notation in the below)
//Stack.h
#ifndef _STACK_
#define _STACK_
#include
using namespace std;
const int MAXSIZE = 1000;
template
class Stack {
private:
int top;
T items[MAXSIZE];
public:
Stack();
bool isEmpty()const;
bool isFull()const;
bool pop(T &topItem);
bool peek(T &res)const;
bool push(const T &item);
};
#endif
//end of Stack.h file
#include "Stack.h"
int main()
{
char *str = "hello world 123";
int i = 0;
Stack
while (str[i] != '\0')
{
s.push(str[i]);
i++;
}
char ch;
while (!s.isEmpty()){
bool popStatus = s.pop(ch) ;
if(popStatus)
cout< } cout< } Infix to Postfix Write a program that converts an infix expression into an equivalent postfix expression. The rules to convert an infix expression into an equivalent postfix expression are as follows: Suppose infx represents the infix expression and pfx represents the postfix expression. The rules to convert infx into pfx are as follows: 1) Initialize pfx to an empty expression and also initialize the stack. 2) While there are symbols in the infx expression, Get the next symbol, sym, from infx. a) If sym is an operand, append sym to pfx. b) If sym is (, push sym into the stack. c) If sym is ), pop and append all the symbols from the stack until the most recent left parenthesis. Pop and discard the left parenthesis. d) If sym is an operator: i) If s is not empty ,Pop and append all the operators from the stack to pfx that are above the most recent left parenthesis and have precedence greater than or equal to sym. ii) Push sym onto the stack. 3) After processing infx, some operators might be left in the stack. Pop and append to pfx everything from the stack. In this program, you will consider the (binary) arithmetic operators: +, -, *, and /, operands are single letters. In valid infix expression operands and operators are delimited with one or more white space. You may assume that the expressions you will process are error free. Design a class that stores the infix and postfix strings. The class must include the following operations: -infix: string -postfix: string +getInfixStores the infix expression +showInfixOutputs the infix expression +showPostfixOutputs the postfix expression Some other operations that you might need are the following: +convertToPostfixConverts the infix expression into a postfix expression. The resulting postfix expression is stored in pfx. -precedenceDetermines the precedence between two operators. If the first operator is higher or equal precedence than the second operator, it returns the value true; otherwise, it returns the value false. Include the constructors and destructors for automatic initialization and dynamic memory deallocation. Test your program on the following five expressions: A + B - C; (A + B ) * C; (A + B) * (C - D); A + ((B + C) * (E - F) - G) / (H - I); A + B * (C + D ) - E / F * G + H; For each expression, your answer must be in the following form: Infix Expression: A + B - C; Postfix Expression: A B + C -
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started