Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include #include using namespace std; // global declation int const null = -1; int const SIZE = 100; int Top = null; //

#include #include #include #include using namespace std; // global declation int const null = -1; int const SIZE = 100; int Top = null; // Top of Stack char Q[SIZE], P[SIZE], Stack[SIZE]; // Q is infix and P is postfix expression array int n = 0; // used to count item inserted in P and index for P

void get_Infix ( ) { cout

// following function will do initial work with Q and stack void step_One( ) { strcat(Q,")"); // This function add ) at the and of Q Push('('); // This statement will push first '(' on Stack }

void convert() { while(Top != null ) { for(int i=0;i

} // closing of the convert function void display( ) { P[n]='\0'; // this statement will put string terminator at the // end of P which is Postfix expression cout

} // closing of the convert function void Push(char item) { if(Top == SIZE-1 ){ cout

} char Pop( ) { return Stack[Top--]; }

bool IsEmpty( ) { if(Top == null ) return true; else return false; }

int main() { get_Infix( ); step_One( ); convert( ); display( ); return 0;

} //END OF MAIN FUNCTION

this is the previoes code --------------------------------------------------------------------------------------------

help with code this my code

Transforming Infix Expression into Postfix Expression:

#include #include #include #include using namespace std; // global declation int const null = -1; int const SIZE = 100; int Top = null; // Top of Stack char Q[SIZE], P[SIZE], Stack[SIZE]; // Q is infix and P is postfix expression array int n = 0; // used to count item inserted in P and index for P void display() {

P[n] = '\0'; // this statement will put string terminator at the // end of P which is Postfix expression cout

} // closing of the convert function void Push(char item) {

if (Top == SIZE - 1) { cout

} char Pop() { return Stack[Top--]; }

bool IsEmpty() { if (Top == null) return true; else return false; } void get_Infix ( ) { cout

// following function will do initial work with Q and stack void step_One( ) { strcat(Q,")"); // This function add ) at the and of Q Push('('); // This statement will push first '(' on Stack }

void convert() { while(Top != null ) { for(int i=0;i

} // closing of the convert function

} } } }

int main() {

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

4. Algorithm: Infix_to_PostFix(Q, P) Suppose Q is an arithmetic expression written in infix notation. This algorithm finds the equivalent postfix expression P. 1. Push "C" onto STACK, and add ")" to the end of Q. 2. Scan Q from left to right and repeat Steps 3 to 6 for each element of Q until the STACK is empty: If an operand is encountered, add it to P. If a left parenthesis is encountered, Push it onto STACK. 5. If an operator is encountered, then: a) Repeatedly Pop from STACK and add to P each operator (on the top of STACK) which has the same or higher precedence/priority than b) Push to STACK. [End of If structure.] 6. If a right parenthesis is encountered, then: a) Repeatedly Pop from STACK and add to P each operator (on the top of STACK) until a left parenthesis is encountered. b) Pop the left parenthesis. [Do not add the left parenthesis to P.] [End of If structure.] [End of Step 2 loop.] 7. End. Source code. Transforming Infix Expression into Postfix Expression: The following algorithm transforms the infix expression Q into its equivalent postfix expression P. It uses a stack to temporary hold the operators and left parenthesis. The postfix expression will be constructed from left to right using operands from Q and operators popped from STACK. Algorithm: Infix_to_PostFix(Q, P) Suppose Q is an arithmetic expression written in infix notation. This algorithm finds the equivalent postfix expression P. 1. Push "("onto STACK, and add ")" to the end of Q. 2. Scan Q from left to right and repeat Steps 3 to 6 for each element of Q until the STACK is empty: 3. If an operand is encountered, add it to P. 4. If a left parenthesis is encountered, Push it onto STACK. 5. If an operator is encountered, then: a) Repeatedly Pop from STACK and add to P each operator (on the top of STACK) which has the same or higher precedence/priority than b) Push o to STACK. [End of If structure.] 6. If a right parenthesis is encountered, then: a) Repeatedly Pop from STACK and add to P each operator (on the top of STACK) until a left parenthesis is encountered. b) Pop the left parenthesis. [Do not add the left parenthesis to P.] [End of If structure.] [End of Step 2 loop.] 7. End. Source code: #include #include #include #include // global declation int const null = -1; int const SIZE = 100; int Top = null; // Top of Stack char Q[SIZE], P[SIZE], Stack[SIZE]; // Q is infix and P is postfix expression array int n = 0; // used to count item inserted in P and index for p void get_Infix () { cout mon *+ (+ (+* (+* 4. Algorithm: Infix_to_PostFix(Q, P) Suppose Q is an arithmetic expression written in infix notation. This algorithm finds the equivalent postfix expression P. 1. Push "C" onto STACK, and add ")" to the end of Q. 2. Scan Q from left to right and repeat Steps 3 to 6 for each element of Q until the STACK is empty: If an operand is encountered, add it to P. If a left parenthesis is encountered, Push it onto STACK. 5. If an operator is encountered, then: a) Repeatedly Pop from STACK and add to P each operator (on the top of STACK) which has the same or higher precedence/priority than b) Push to STACK. [End of If structure.] 6. If a right parenthesis is encountered, then: a) Repeatedly Pop from STACK and add to P each operator (on the top of STACK) until a left parenthesis is encountered. b) Pop the left parenthesis. [Do not add the left parenthesis to P.] [End of If structure.] [End of Step 2 loop.] 7. End. Source code. Transforming Infix Expression into Postfix Expression: The following algorithm transforms the infix expression Q into its equivalent postfix expression P. It uses a stack to temporary hold the operators and left parenthesis. The postfix expression will be constructed from left to right using operands from Q and operators popped from STACK. Algorithm: Infix_to_PostFix(Q, P) Suppose Q is an arithmetic expression written in infix notation. This algorithm finds the equivalent postfix expression P. 1. Push "("onto STACK, and add ")" to the end of Q. 2. Scan Q from left to right and repeat Steps 3 to 6 for each element of Q until the STACK is empty: 3. If an operand is encountered, add it to P. 4. If a left parenthesis is encountered, Push it onto STACK. 5. If an operator is encountered, then: a) Repeatedly Pop from STACK and add to P each operator (on the top of STACK) which has the same or higher precedence/priority than b) Push o to STACK. [End of If structure.] 6. If a right parenthesis is encountered, then: a) Repeatedly Pop from STACK and add to P each operator (on the top of STACK) until a left parenthesis is encountered. b) Pop the left parenthesis. [Do not add the left parenthesis to P.] [End of If structure.] [End of Step 2 loop.] 7. End. Source code: #include #include #include #include // global declation int const null = -1; int const SIZE = 100; int Top = null; // Top of Stack char Q[SIZE], P[SIZE], Stack[SIZE]; // Q is infix and P is postfix expression array int n = 0; // used to count item inserted in P and index for p void get_Infix () { cout mon *+ (+ (+* (+*

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 Programming Languages 12th International Symposium Dbpl 2009 Lyon France August 2009 Proceedings Lncs 5708

Authors: Philippa Gardner ,Floris Geerts

2009th Edition

3642037925, 978-3642037924

More Books

Students also viewed these Databases questions

Question

Discuss five types of employee training.

Answered: 1 week ago

Question

Identify the four federally mandated employee benefits.

Answered: 1 week ago