SlideShare a Scribd company logo
1 of 9
Download to read offline
2. Stack. Write a program that uses the stack class (you can use the stack type defined in the
lectures, or you can define your own stack type) to solve a problem. The problem contains two
tasks, the first one is to convert an infix arithmetic expression into a postfix arithmetic
expression; the second task is to evaluate arithmetic expressions written in postfix form.
In infix form, the operator of an arithmetic statement is in-between every pair of operands. For
example:
1.5 + 2.3
2.0 * (3.3 + 4.5)
(2.1 + 3.0) * 4.8
In postfix form, the operands of an arithmetic statement appear followed by the operator. One of
the virtues of postfix form is that expressions can be written without the need for parentheses.
Here are some examples of arithmetic expressions written in postfix form:
1.5 2.3 + // Equivalent to 1.5 + 2.3
2.0 3.3 4.5 + * // Equivalent to 2.0 * (3.3 + 4.5)
2.1 3.3 + 4.8 * // Equivalent to (2.1 + 3.0) * 4.8
Please write a C++ program that uses an operator stack to convert an infix arithmetic expression
that the user enters into a postfix arithmetic expression, and then use a float stack to evaluate
postfix arithmetic.
Your program should support all five of the arithmetic operators, +, - , *, and /.
When users input the infix arithmetic expressions, the operands, operators and parenthesis
symbols are separated by spaces. The character # marks the end of the expression.
The infix arithmetic expressions only contain operands, operators and parenthesis. The operands
are float numbers, and the operators are +, -, * and /. If there are letters in the infix arithmetic
expressions, the “invalid expression” message should be displayed.
Here is an algorithm for evaluating an arithmetic expression written in postfix form with the aid
of a stack of floats.
• Scan the expression from left to right.
• When encounter an operand or a float, push it on the stack.
• When encounter an arithmetic operator, pop the top two numbers off the stack and use them as
operands for the indicated operation. Push the resulting number back on the stack.
• when you reach the end of the expression, the result of the calculation should be the sole item
on the stack.
Please show that that the program is working correctly by converting the following infix
arithmetic expressions and then computing the obtained postfix arithmetic expressions:
6.5 * 6.5 - 4 * 1.5 * 1.44 #
3.1 * (2.5 + 4.7 * 1.6) + 8.6 #
70.0 - (10.5 + 6) / 0.5 + 18.2 #
The following steps will convert an infix expression into a postfix expression:
1. Create an empty string stack called opStack for keeping operators. Create an empty string
array called postfixEx for postfix expression.
2. read the infix expression left to right.
2.1. If the string is an operand, append it to the postfixEx array.
2.2. If the string is a left parenthesis, push it on the opStack.
2.3. If the string is a right parenthesis, pop the opStack, append each operator to the postfixEx
array, until you see the corresponding left parenthesis, discard the pair of parentheses.
2.4. If the string is an operator, *, /, +, or -, first remove any operators already on the opStack
that have higher or equal precedence and append them to the postfixEx array, then push the
current operator on the opStack.
3. When the input infix expression has been completely processed, check the opstack, any
operators still on the stack can be removed and appended to the end of the postfixEx array.
2. Stack. Write a program that uses the stack class (you can use the stack type defined in the
lectures, or you can define your own stack type) to solve a problem. The problem contains two
tasks, the first one is to convert an infix arithmetic expression into a postfix arithmetic
expression; the second task is to evaluate arithmetic expressions written in postfix form.
In infix form, the operator of an arithmetic statement is in-between every pair of operands. For
example:
1.5 + 2.3
2.0 * (3.3 + 4.5)
(2.1 + 3.0) * 4.8
In postfix form, the operands of an arithmetic statement appear followed by the operator. One of
the virtues of postfix form is that expressions can be written without the need for parentheses.
Here are some examples of arithmetic expressions written in postfix form:
1.5 2.3 + // Equivalent to 1.5 + 2.3
2.0 3.3 4.5 + * // Equivalent to 2.0 * (3.3 + 4.5)
2.1 3.3 + 4.8 * // Equivalent to (2.1 + 3.0) * 4.8
Please write a C++ program that uses an operator stack to convert an infix arithmetic expression
that the user enters into a postfix arithmetic expression, and then use a float stack to evaluate
postfix arithmetic.
Your program should support all five of the arithmetic operators, +, - , *, and /.
When users input the infix arithmetic expressions, the operands, operators and parenthesis
symbols are separated by spaces. The character # marks the end of the expression.
The infix arithmetic expressions only contain operands, operators and parenthesis. The operands
are float numbers, and the operators are +, -, * and /. If there are letters in the infix arithmetic
expressions, the “invalid expression” message should be displayed.
Here is an algorithm for evaluating an arithmetic expression written in postfix form with the aid
of a stack of floats.
• Scan the expression from left to right.
• When encounter an operand or a float, push it on the stack.
• When encounter an arithmetic operator, pop the top two numbers off the stack and use them as
operands for the indicated operation. Push the resulting number back on the stack.
• when you reach the end of the expression, the result of the calculation should be the sole item
on the stack.
Please show that that the program is working correctly by converting the following infix
arithmetic expressions and then computing the obtained postfix arithmetic expressions:
6.5 * 6.5 - 4 * 1.5 * 1.44 #
3.1 * (2.5 + 4.7 * 1.6) + 8.6 #
70.0 - (10.5 + 6) / 0.5 + 18.2 #
The following steps will convert an infix expression into a postfix expression:
1. Create an empty string stack called opStack for keeping operators. Create an empty string
array called postfixEx for postfix expression.
2. read the infix expression left to right.
2.1. If the string is an operand, append it to the postfixEx array.
2.2. If the string is a left parenthesis, push it on the opStack.
2.3. If the string is a right parenthesis, pop the opStack, append each operator to the postfixEx
array, until you see the corresponding left parenthesis, discard the pair of parentheses.
2.4. If the string is an operator, *, /, +, or -, first remove any operators already on the opStack
that have higher or equal precedence and append them to the postfixEx array, then push the
current operator on the opStack.
3. When the input infix expression has been completely processed, check the opstack, any
operators still on the stack can be removed and appended to the end of the postfixEx array.
2. Stack. Write a program that uses the stack class (you can use the stack type defined in the
lectures, or you can define your own stack type) to solve a problem. The problem contains two
tasks, the first one is to convert an infix arithmetic expression into a postfix arithmetic
expression; the second task is to evaluate arithmetic expressions written in postfix form.
In infix form, the operator of an arithmetic statement is in-between every pair of operands. For
example:
1.5 + 2.3
2.0 * (3.3 + 4.5)
(2.1 + 3.0) * 4.8
In postfix form, the operands of an arithmetic statement appear followed by the operator. One of
the virtues of postfix form is that expressions can be written without the need for parentheses.
Here are some examples of arithmetic expressions written in postfix form:
1.5 2.3 + // Equivalent to 1.5 + 2.3
2.0 3.3 4.5 + * // Equivalent to 2.0 * (3.3 + 4.5)
2.1 3.3 + 4.8 * // Equivalent to (2.1 + 3.0) * 4.8
Please write a C++ program that uses an operator stack to convert an infix arithmetic expression
that the user enters into a postfix arithmetic expression, and then use a float stack to evaluate
postfix arithmetic.
Your program should support all five of the arithmetic operators, +, - , *, and /.
When users input the infix arithmetic expressions, the operands, operators and parenthesis
symbols are separated by spaces. The character # marks the end of the expression.
The infix arithmetic expressions only contain operands, operators and parenthesis. The operands
are float numbers, and the operators are +, -, * and /. If there are letters in the infix arithmetic
expressions, the “invalid expression” message should be displayed.
Here is an algorithm for evaluating an arithmetic expression written in postfix form with the aid
of a stack of floats.
• Scan the expression from left to right.
• When encounter an operand or a float, push it on the stack.
• When encounter an arithmetic operator, pop the top two numbers off the stack and use them as
operands for the indicated operation. Push the resulting number back on the stack.
• when you reach the end of the expression, the result of the calculation should be the sole item
on the stack.
Please show that that the program is working correctly by converting the following infix
arithmetic expressions and then computing the obtained postfix arithmetic expressions:
6.5 * 6.5 - 4 * 1.5 * 1.44 #
3.1 * (2.5 + 4.7 * 1.6) + 8.6 #
70.0 - (10.5 + 6) / 0.5 + 18.2 #
The following steps will convert an infix expression into a postfix expression:
1. Create an empty string stack called opStack for keeping operators. Create an empty string
array called postfixEx for postfix expression.
2. read the infix expression left to right.
2.1. If the string is an operand, append it to the postfixEx array.
2.2. If the string is a left parenthesis, push it on the opStack.
2.3. If the string is a right parenthesis, pop the opStack, append each operator to the postfixEx
array, until you see the corresponding left parenthesis, discard the pair of parentheses.
2.4. If the string is an operator, *, /, +, or -, first remove any operators already on the opStack
that have higher or equal precedence and append them to the postfixEx array, then push the
current operator on the opStack.
3. When the input infix expression has been completely processed, check the opstack, any
operators still on the stack can be removed and appended to the end of the postfixEx array.
The following steps will convert an infix expression into a postfix expression:
1. Create an empty string stack called opStack for keeping operators. Create an empty string
array called postfixEx for postfix expression.
2. read the infix expression left to right.
2.1. If the string is an operand, append it to the postfixEx array.
2.2. If the string is a left parenthesis, push it on the opStack.
2.3. If the string is a right parenthesis, pop the opStack, append each operator to the postfixEx
array, until you see the corresponding left parenthesis, discard the pair of parentheses.
2.4. If the string is an operator, *, /, +, or -, first remove any operators already on the opStack
that have higher or equal precedence and append them to the postfixEx array, then push the
current operator on the opStack.
3. When the input infix expression has been completely processed, check the opstack, any
operators still on the stack can be removed and appended to the end of the postfixEx array.
Solution
#include
#include
#include
#include
using namespace std;
int eval(int op1, int op2, char operate) {
switch (operate) {
case '*': return op2 * op1;
case '/': return op2 / op1;
case '+': return op2 + op1;
case '-': return op2 - op1;
default : return 0;
}
}
int getpre(char ch) {
switch (ch) {
case '/':
case '*': return 2;
case '+':
case '-': return 1;
default : return 0;
}
}
void in2pos(char infix[], char postfix[], int size) {
stack s;
int pre;
int i = 0;
int k = 0;
char ch;
while (i < size) {
ch = infix[i];
if (ch == '(') {
s.push(ch);
i++;
continue;
}
if (ch == ')') {
while (!s.empty() && s.top() != '(') {
postfix[k++] = s.top();
s.pop();
}
if (!s.empty()) {
s.pop();
}
i++;
continue;
}
pre = getpre(ch);
if (pre == 0) {
postfix[k++] = ch;
}
else {
if (s.empty()) {
s.push(ch);
}
else {
while (!s.empty() && s.top() != '(' &&
pre <= getpre(s.top())) {
postfix[k++] = s.top();
s.pop();
}
s.push(ch);
}
}
i++;
}
while (!s.empty()) {
postfix[k++] = s.top();
s.pop();
}
postfix[k] = 0;
}
int evalpos(char postfix[], int size) {
stack s;
int i = 0;
char ch;
int val;
while (i < size) {
ch = postfix[i];
if (isdigit(ch)) {
s.push(ch-'0');
}
else {
int op1 = s.top();
s.pop();
int op2 = s.top();
s.pop();
val = eval(op1, op2, ch);
s.push(val);
}
i++;
}
return val;
}
int main() {
const int max = 10;
char infix[max] = {0};
int f;
cout << "Please enter infix expression: " << endl;
cin>>infix;
int size = strlen(infix);
char postfix[size];
in2pos(infix,postfix,size);
cout<<" Infix Expression :: "<>f;
return 0;
}

More Related Content

Similar to 2. Stack. Write a program that uses the stack class (you can use.pdf

1.4 expression tree
1.4 expression tree  1.4 expression tree
1.4 expression tree Krish_ver2
 
Unit 3 Stacks and Queues.pptx
Unit 3 Stacks and Queues.pptxUnit 3 Stacks and Queues.pptx
Unit 3 Stacks and Queues.pptxYogesh Pawar
 
Lecture_04.2.pptx
Lecture_04.2.pptxLecture_04.2.pptx
Lecture_04.2.pptxRockyIslam5
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manualnikshaikh786
 
stack-111104232459-phpapp02.pdf
stack-111104232459-phpapp02.pdfstack-111104232459-phpapp02.pdf
stack-111104232459-phpapp02.pdfKalpana Mohan
 
Using RustBecause postfix expressions are simpler and faster to ev.pdf
Using RustBecause postfix expressions are simpler and faster to ev.pdfUsing RustBecause postfix expressions are simpler and faster to ev.pdf
Using RustBecause postfix expressions are simpler and faster to ev.pdfdeepaksatrker
 
Linear Data Structures_SSD.pdf
Linear Data Structures_SSD.pdfLinear Data Structures_SSD.pdf
Linear Data Structures_SSD.pdfssuser37b0e0
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-listpinakspatel
 
Description of a JAVA programYou are to write a program name Infi.pdf
Description of a JAVA programYou are to write a program name Infi.pdfDescription of a JAVA programYou are to write a program name Infi.pdf
Description of a JAVA programYou are to write a program name Infi.pdfarumugambags
 
COMP1603 Stacks and RPN 2023 Recording (2).pptx
COMP1603 Stacks and RPN 2023 Recording (2).pptxCOMP1603 Stacks and RPN 2023 Recording (2).pptx
COMP1603 Stacks and RPN 2023 Recording (2).pptxasdadad5
 
Unit II - LINEAR DATA STRUCTURES
Unit II -  LINEAR DATA STRUCTURESUnit II -  LINEAR DATA STRUCTURES
Unit II - LINEAR DATA STRUCTURESUsha Mahalingam
 
Description of programYou are to write a program name InfixToPost.pdf
Description of programYou are to write a program name InfixToPost.pdfDescription of programYou are to write a program name InfixToPost.pdf
Description of programYou are to write a program name InfixToPost.pdfarihantelehyb
 
Getting started with c++.pptx
Getting started with c++.pptxGetting started with c++.pptx
Getting started with c++.pptxAkash Baruah
 
Stack_Overview_Implementation_WithVode.pptx
Stack_Overview_Implementation_WithVode.pptxStack_Overview_Implementation_WithVode.pptx
Stack_Overview_Implementation_WithVode.pptxchandankumar364348
 
Infix to Postfix Conversion.pdf
Infix to Postfix Conversion.pdfInfix to Postfix Conversion.pdf
Infix to Postfix Conversion.pdfayushi296420
 
This first assignment will focus on coding in Python, applying kno.docx
This first assignment will focus on coding in Python, applying kno.docxThis first assignment will focus on coding in Python, applying kno.docx
This first assignment will focus on coding in Python, applying kno.docxabhi353063
 

Similar to 2. Stack. Write a program that uses the stack class (you can use.pdf (20)

1.4 expression tree
1.4 expression tree  1.4 expression tree
1.4 expression tree
 
Unit 3 Stacks and Queues.pptx
Unit 3 Stacks and Queues.pptxUnit 3 Stacks and Queues.pptx
Unit 3 Stacks and Queues.pptx
 
Lecture_04.2.pptx
Lecture_04.2.pptxLecture_04.2.pptx
Lecture_04.2.pptx
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
 
stack-111104232459-phpapp02.pdf
stack-111104232459-phpapp02.pdfstack-111104232459-phpapp02.pdf
stack-111104232459-phpapp02.pdf
 
Stack application
Stack applicationStack application
Stack application
 
Using RustBecause postfix expressions are simpler and faster to ev.pdf
Using RustBecause postfix expressions are simpler and faster to ev.pdfUsing RustBecause postfix expressions are simpler and faster to ev.pdf
Using RustBecause postfix expressions are simpler and faster to ev.pdf
 
Linear Data Structures_SSD.pdf
Linear Data Structures_SSD.pdfLinear Data Structures_SSD.pdf
Linear Data Structures_SSD.pdf
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
 
Description of a JAVA programYou are to write a program name Infi.pdf
Description of a JAVA programYou are to write a program name Infi.pdfDescription of a JAVA programYou are to write a program name Infi.pdf
Description of a JAVA programYou are to write a program name Infi.pdf
 
COMP1603 Stacks and RPN 2023 Recording (2).pptx
COMP1603 Stacks and RPN 2023 Recording (2).pptxCOMP1603 Stacks and RPN 2023 Recording (2).pptx
COMP1603 Stacks and RPN 2023 Recording (2).pptx
 
Unit II - LINEAR DATA STRUCTURES
Unit II -  LINEAR DATA STRUCTURESUnit II -  LINEAR DATA STRUCTURES
Unit II - LINEAR DATA STRUCTURES
 
Description of programYou are to write a program name InfixToPost.pdf
Description of programYou are to write a program name InfixToPost.pdfDescription of programYou are to write a program name InfixToPost.pdf
Description of programYou are to write a program name InfixToPost.pdf
 
Getting started with c++.pptx
Getting started with c++.pptxGetting started with c++.pptx
Getting started with c++.pptx
 
Stack_Overview_Implementation_WithVode.pptx
Stack_Overview_Implementation_WithVode.pptxStack_Overview_Implementation_WithVode.pptx
Stack_Overview_Implementation_WithVode.pptx
 
Infix to Postfix Conversion.pdf
Infix to Postfix Conversion.pdfInfix to Postfix Conversion.pdf
Infix to Postfix Conversion.pdf
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
This first assignment will focus on coding in Python, applying kno.docx
This first assignment will focus on coding in Python, applying kno.docxThis first assignment will focus on coding in Python, applying kno.docx
This first assignment will focus on coding in Python, applying kno.docx
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
 
Infix to postfix conversion
Infix to postfix conversionInfix to postfix conversion
Infix to postfix conversion
 

More from aniarihant

Im suppose to make a preOrder transversal method so that it performs.pdf
Im suppose to make a preOrder transversal method so that it performs.pdfIm suppose to make a preOrder transversal method so that it performs.pdf
Im suppose to make a preOrder transversal method so that it performs.pdfaniarihant
 
Give an explanation of the pedigree below. SolutionThe inherit.pdf
Give an explanation of the pedigree below.  SolutionThe inherit.pdfGive an explanation of the pedigree below.  SolutionThe inherit.pdf
Give an explanation of the pedigree below. SolutionThe inherit.pdfaniarihant
 
elena ents you to impact into MAt ab SolutionThree fu.pdf
elena ents you to impact into MAt ab SolutionThree fu.pdfelena ents you to impact into MAt ab SolutionThree fu.pdf
elena ents you to impact into MAt ab SolutionThree fu.pdfaniarihant
 
Ecosystem ecologyCompare and contrast abiotic gradients in a tempe.pdf
Ecosystem ecologyCompare and contrast abiotic gradients in a tempe.pdfEcosystem ecologyCompare and contrast abiotic gradients in a tempe.pdf
Ecosystem ecologyCompare and contrast abiotic gradients in a tempe.pdfaniarihant
 
Compare and contrast ClearCase and ClearQuest.SolutionClearcas.pdf
Compare and contrast ClearCase and ClearQuest.SolutionClearcas.pdfCompare and contrast ClearCase and ClearQuest.SolutionClearcas.pdf
Compare and contrast ClearCase and ClearQuest.SolutionClearcas.pdfaniarihant
 
Assume that you have a garden and some pea plants have solid leaves a.pdf
Assume that you have a garden and some pea plants have solid leaves a.pdfAssume that you have a garden and some pea plants have solid leaves a.pdf
Assume that you have a garden and some pea plants have solid leaves a.pdfaniarihant
 
According to NASA GISS measurements, the years 2005 and 2010 are tied.pdf
According to NASA GISS measurements, the years 2005 and 2010 are tied.pdfAccording to NASA GISS measurements, the years 2005 and 2010 are tied.pdf
According to NASA GISS measurements, the years 2005 and 2010 are tied.pdfaniarihant
 
A drawer contains 6 blue and 4 white socks. Two of the socks are chos.pdf
A drawer contains 6 blue and 4 white socks. Two of the socks are chos.pdfA drawer contains 6 blue and 4 white socks. Two of the socks are chos.pdf
A drawer contains 6 blue and 4 white socks. Two of the socks are chos.pdfaniarihant
 
Bill is outside on a snowy day without a warm coat. His skin is al.pdf
Bill is outside on a snowy day without a warm coat. His skin is al.pdfBill is outside on a snowy day without a warm coat. His skin is al.pdf
Bill is outside on a snowy day without a warm coat. His skin is al.pdfaniarihant
 
As a network administrator, what are some of the options you have fo.pdf
As a network administrator, what are some of the options you have fo.pdfAs a network administrator, what are some of the options you have fo.pdf
As a network administrator, what are some of the options you have fo.pdfaniarihant
 
A concert has three pieces of music to be played before intermission.pdf
A concert has three pieces of music to be played before intermission.pdfA concert has three pieces of music to be played before intermission.pdf
A concert has three pieces of music to be played before intermission.pdfaniarihant
 
5 of 50 students are female. If I randomly selects 10 students witho.pdf
5 of 50 students are female. If I randomly selects 10 students witho.pdf5 of 50 students are female. If I randomly selects 10 students witho.pdf
5 of 50 students are female. If I randomly selects 10 students witho.pdfaniarihant
 
Which if statement below tests if letter holds R (letter is a char .pdf
Which if statement below tests if letter holds R (letter is a char .pdfWhich if statement below tests if letter holds R (letter is a char .pdf
Which if statement below tests if letter holds R (letter is a char .pdfaniarihant
 
Write a assembly program for IA-32 to count up the number of even num.pdf
Write a assembly program for IA-32 to count up the number of even num.pdfWrite a assembly program for IA-32 to count up the number of even num.pdf
Write a assembly program for IA-32 to count up the number of even num.pdfaniarihant
 
Which of the following is a weighted average of some elements having .pdf
Which of the following is a weighted average of some elements having .pdfWhich of the following is a weighted average of some elements having .pdf
Which of the following is a weighted average of some elements having .pdfaniarihant
 
Which of the following statements isare true about the graph of the .pdf
Which of the following statements isare true about the graph of the .pdfWhich of the following statements isare true about the graph of the .pdf
Which of the following statements isare true about the graph of the .pdfaniarihant
 
35. 2H H2 has E0 of -0.42 and NoihN2 has Eo of +0.74. Which is the .pdf
35. 2H H2 has E0 of -0.42 and NoihN2 has Eo of +0.74. Which is the .pdf35. 2H H2 has E0 of -0.42 and NoihN2 has Eo of +0.74. Which is the .pdf
35. 2H H2 has E0 of -0.42 and NoihN2 has Eo of +0.74. Which is the .pdfaniarihant
 
6. A more in depth look at how to recognize “true adaptation”. Skim .pdf
6. A more in depth look at how to recognize “true adaptation”. Skim .pdf6. A more in depth look at how to recognize “true adaptation”. Skim .pdf
6. A more in depth look at how to recognize “true adaptation”. Skim .pdfaniarihant
 
What does antibody titer meanSolution It is a method for t.pdf
What does antibody titer meanSolution  It is a method for t.pdfWhat does antibody titer meanSolution  It is a method for t.pdf
What does antibody titer meanSolution It is a method for t.pdfaniarihant
 
What role do regular expressions typically play in language compiler.pdf
What role do regular expressions typically play in language compiler.pdfWhat role do regular expressions typically play in language compiler.pdf
What role do regular expressions typically play in language compiler.pdfaniarihant
 

More from aniarihant (20)

Im suppose to make a preOrder transversal method so that it performs.pdf
Im suppose to make a preOrder transversal method so that it performs.pdfIm suppose to make a preOrder transversal method so that it performs.pdf
Im suppose to make a preOrder transversal method so that it performs.pdf
 
Give an explanation of the pedigree below. SolutionThe inherit.pdf
Give an explanation of the pedigree below.  SolutionThe inherit.pdfGive an explanation of the pedigree below.  SolutionThe inherit.pdf
Give an explanation of the pedigree below. SolutionThe inherit.pdf
 
elena ents you to impact into MAt ab SolutionThree fu.pdf
elena ents you to impact into MAt ab SolutionThree fu.pdfelena ents you to impact into MAt ab SolutionThree fu.pdf
elena ents you to impact into MAt ab SolutionThree fu.pdf
 
Ecosystem ecologyCompare and contrast abiotic gradients in a tempe.pdf
Ecosystem ecologyCompare and contrast abiotic gradients in a tempe.pdfEcosystem ecologyCompare and contrast abiotic gradients in a tempe.pdf
Ecosystem ecologyCompare and contrast abiotic gradients in a tempe.pdf
 
Compare and contrast ClearCase and ClearQuest.SolutionClearcas.pdf
Compare and contrast ClearCase and ClearQuest.SolutionClearcas.pdfCompare and contrast ClearCase and ClearQuest.SolutionClearcas.pdf
Compare and contrast ClearCase and ClearQuest.SolutionClearcas.pdf
 
Assume that you have a garden and some pea plants have solid leaves a.pdf
Assume that you have a garden and some pea plants have solid leaves a.pdfAssume that you have a garden and some pea plants have solid leaves a.pdf
Assume that you have a garden and some pea plants have solid leaves a.pdf
 
According to NASA GISS measurements, the years 2005 and 2010 are tied.pdf
According to NASA GISS measurements, the years 2005 and 2010 are tied.pdfAccording to NASA GISS measurements, the years 2005 and 2010 are tied.pdf
According to NASA GISS measurements, the years 2005 and 2010 are tied.pdf
 
A drawer contains 6 blue and 4 white socks. Two of the socks are chos.pdf
A drawer contains 6 blue and 4 white socks. Two of the socks are chos.pdfA drawer contains 6 blue and 4 white socks. Two of the socks are chos.pdf
A drawer contains 6 blue and 4 white socks. Two of the socks are chos.pdf
 
Bill is outside on a snowy day without a warm coat. His skin is al.pdf
Bill is outside on a snowy day without a warm coat. His skin is al.pdfBill is outside on a snowy day without a warm coat. His skin is al.pdf
Bill is outside on a snowy day without a warm coat. His skin is al.pdf
 
As a network administrator, what are some of the options you have fo.pdf
As a network administrator, what are some of the options you have fo.pdfAs a network administrator, what are some of the options you have fo.pdf
As a network administrator, what are some of the options you have fo.pdf
 
A concert has three pieces of music to be played before intermission.pdf
A concert has three pieces of music to be played before intermission.pdfA concert has three pieces of music to be played before intermission.pdf
A concert has three pieces of music to be played before intermission.pdf
 
5 of 50 students are female. If I randomly selects 10 students witho.pdf
5 of 50 students are female. If I randomly selects 10 students witho.pdf5 of 50 students are female. If I randomly selects 10 students witho.pdf
5 of 50 students are female. If I randomly selects 10 students witho.pdf
 
Which if statement below tests if letter holds R (letter is a char .pdf
Which if statement below tests if letter holds R (letter is a char .pdfWhich if statement below tests if letter holds R (letter is a char .pdf
Which if statement below tests if letter holds R (letter is a char .pdf
 
Write a assembly program for IA-32 to count up the number of even num.pdf
Write a assembly program for IA-32 to count up the number of even num.pdfWrite a assembly program for IA-32 to count up the number of even num.pdf
Write a assembly program for IA-32 to count up the number of even num.pdf
 
Which of the following is a weighted average of some elements having .pdf
Which of the following is a weighted average of some elements having .pdfWhich of the following is a weighted average of some elements having .pdf
Which of the following is a weighted average of some elements having .pdf
 
Which of the following statements isare true about the graph of the .pdf
Which of the following statements isare true about the graph of the .pdfWhich of the following statements isare true about the graph of the .pdf
Which of the following statements isare true about the graph of the .pdf
 
35. 2H H2 has E0 of -0.42 and NoihN2 has Eo of +0.74. Which is the .pdf
35. 2H H2 has E0 of -0.42 and NoihN2 has Eo of +0.74. Which is the .pdf35. 2H H2 has E0 of -0.42 and NoihN2 has Eo of +0.74. Which is the .pdf
35. 2H H2 has E0 of -0.42 and NoihN2 has Eo of +0.74. Which is the .pdf
 
6. A more in depth look at how to recognize “true adaptation”. Skim .pdf
6. A more in depth look at how to recognize “true adaptation”. Skim .pdf6. A more in depth look at how to recognize “true adaptation”. Skim .pdf
6. A more in depth look at how to recognize “true adaptation”. Skim .pdf
 
What does antibody titer meanSolution It is a method for t.pdf
What does antibody titer meanSolution  It is a method for t.pdfWhat does antibody titer meanSolution  It is a method for t.pdf
What does antibody titer meanSolution It is a method for t.pdf
 
What role do regular expressions typically play in language compiler.pdf
What role do regular expressions typically play in language compiler.pdfWhat role do regular expressions typically play in language compiler.pdf
What role do regular expressions typically play in language compiler.pdf
 

Recently uploaded

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 

Recently uploaded (20)

Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 

2. Stack. Write a program that uses the stack class (you can use.pdf

  • 1. 2. Stack. Write a program that uses the stack class (you can use the stack type defined in the lectures, or you can define your own stack type) to solve a problem. The problem contains two tasks, the first one is to convert an infix arithmetic expression into a postfix arithmetic expression; the second task is to evaluate arithmetic expressions written in postfix form. In infix form, the operator of an arithmetic statement is in-between every pair of operands. For example: 1.5 + 2.3 2.0 * (3.3 + 4.5) (2.1 + 3.0) * 4.8 In postfix form, the operands of an arithmetic statement appear followed by the operator. One of the virtues of postfix form is that expressions can be written without the need for parentheses. Here are some examples of arithmetic expressions written in postfix form: 1.5 2.3 + // Equivalent to 1.5 + 2.3 2.0 3.3 4.5 + * // Equivalent to 2.0 * (3.3 + 4.5) 2.1 3.3 + 4.8 * // Equivalent to (2.1 + 3.0) * 4.8 Please write a C++ program that uses an operator stack to convert an infix arithmetic expression that the user enters into a postfix arithmetic expression, and then use a float stack to evaluate postfix arithmetic. Your program should support all five of the arithmetic operators, +, - , *, and /. When users input the infix arithmetic expressions, the operands, operators and parenthesis symbols are separated by spaces. The character # marks the end of the expression. The infix arithmetic expressions only contain operands, operators and parenthesis. The operands are float numbers, and the operators are +, -, * and /. If there are letters in the infix arithmetic expressions, the “invalid expression” message should be displayed. Here is an algorithm for evaluating an arithmetic expression written in postfix form with the aid of a stack of floats. • Scan the expression from left to right. • When encounter an operand or a float, push it on the stack. • When encounter an arithmetic operator, pop the top two numbers off the stack and use them as operands for the indicated operation. Push the resulting number back on the stack. • when you reach the end of the expression, the result of the calculation should be the sole item on the stack.
  • 2. Please show that that the program is working correctly by converting the following infix arithmetic expressions and then computing the obtained postfix arithmetic expressions: 6.5 * 6.5 - 4 * 1.5 * 1.44 # 3.1 * (2.5 + 4.7 * 1.6) + 8.6 # 70.0 - (10.5 + 6) / 0.5 + 18.2 # The following steps will convert an infix expression into a postfix expression: 1. Create an empty string stack called opStack for keeping operators. Create an empty string array called postfixEx for postfix expression. 2. read the infix expression left to right. 2.1. If the string is an operand, append it to the postfixEx array. 2.2. If the string is a left parenthesis, push it on the opStack. 2.3. If the string is a right parenthesis, pop the opStack, append each operator to the postfixEx array, until you see the corresponding left parenthesis, discard the pair of parentheses. 2.4. If the string is an operator, *, /, +, or -, first remove any operators already on the opStack that have higher or equal precedence and append them to the postfixEx array, then push the current operator on the opStack. 3. When the input infix expression has been completely processed, check the opstack, any operators still on the stack can be removed and appended to the end of the postfixEx array. 2. Stack. Write a program that uses the stack class (you can use the stack type defined in the lectures, or you can define your own stack type) to solve a problem. The problem contains two tasks, the first one is to convert an infix arithmetic expression into a postfix arithmetic expression; the second task is to evaluate arithmetic expressions written in postfix form. In infix form, the operator of an arithmetic statement is in-between every pair of operands. For example: 1.5 + 2.3 2.0 * (3.3 + 4.5) (2.1 + 3.0) * 4.8 In postfix form, the operands of an arithmetic statement appear followed by the operator. One of the virtues of postfix form is that expressions can be written without the need for parentheses. Here are some examples of arithmetic expressions written in postfix form: 1.5 2.3 + // Equivalent to 1.5 + 2.3
  • 3. 2.0 3.3 4.5 + * // Equivalent to 2.0 * (3.3 + 4.5) 2.1 3.3 + 4.8 * // Equivalent to (2.1 + 3.0) * 4.8 Please write a C++ program that uses an operator stack to convert an infix arithmetic expression that the user enters into a postfix arithmetic expression, and then use a float stack to evaluate postfix arithmetic. Your program should support all five of the arithmetic operators, +, - , *, and /. When users input the infix arithmetic expressions, the operands, operators and parenthesis symbols are separated by spaces. The character # marks the end of the expression. The infix arithmetic expressions only contain operands, operators and parenthesis. The operands are float numbers, and the operators are +, -, * and /. If there are letters in the infix arithmetic expressions, the “invalid expression” message should be displayed. Here is an algorithm for evaluating an arithmetic expression written in postfix form with the aid of a stack of floats. • Scan the expression from left to right. • When encounter an operand or a float, push it on the stack. • When encounter an arithmetic operator, pop the top two numbers off the stack and use them as operands for the indicated operation. Push the resulting number back on the stack. • when you reach the end of the expression, the result of the calculation should be the sole item on the stack. Please show that that the program is working correctly by converting the following infix arithmetic expressions and then computing the obtained postfix arithmetic expressions: 6.5 * 6.5 - 4 * 1.5 * 1.44 # 3.1 * (2.5 + 4.7 * 1.6) + 8.6 # 70.0 - (10.5 + 6) / 0.5 + 18.2 # The following steps will convert an infix expression into a postfix expression: 1. Create an empty string stack called opStack for keeping operators. Create an empty string array called postfixEx for postfix expression. 2. read the infix expression left to right. 2.1. If the string is an operand, append it to the postfixEx array. 2.2. If the string is a left parenthesis, push it on the opStack. 2.3. If the string is a right parenthesis, pop the opStack, append each operator to the postfixEx
  • 4. array, until you see the corresponding left parenthesis, discard the pair of parentheses. 2.4. If the string is an operator, *, /, +, or -, first remove any operators already on the opStack that have higher or equal precedence and append them to the postfixEx array, then push the current operator on the opStack. 3. When the input infix expression has been completely processed, check the opstack, any operators still on the stack can be removed and appended to the end of the postfixEx array. 2. Stack. Write a program that uses the stack class (you can use the stack type defined in the lectures, or you can define your own stack type) to solve a problem. The problem contains two tasks, the first one is to convert an infix arithmetic expression into a postfix arithmetic expression; the second task is to evaluate arithmetic expressions written in postfix form. In infix form, the operator of an arithmetic statement is in-between every pair of operands. For example: 1.5 + 2.3 2.0 * (3.3 + 4.5) (2.1 + 3.0) * 4.8 In postfix form, the operands of an arithmetic statement appear followed by the operator. One of the virtues of postfix form is that expressions can be written without the need for parentheses. Here are some examples of arithmetic expressions written in postfix form: 1.5 2.3 + // Equivalent to 1.5 + 2.3 2.0 3.3 4.5 + * // Equivalent to 2.0 * (3.3 + 4.5) 2.1 3.3 + 4.8 * // Equivalent to (2.1 + 3.0) * 4.8 Please write a C++ program that uses an operator stack to convert an infix arithmetic expression that the user enters into a postfix arithmetic expression, and then use a float stack to evaluate postfix arithmetic. Your program should support all five of the arithmetic operators, +, - , *, and /. When users input the infix arithmetic expressions, the operands, operators and parenthesis symbols are separated by spaces. The character # marks the end of the expression. The infix arithmetic expressions only contain operands, operators and parenthesis. The operands are float numbers, and the operators are +, -, * and /. If there are letters in the infix arithmetic expressions, the “invalid expression” message should be displayed. Here is an algorithm for evaluating an arithmetic expression written in postfix form with the aid of a stack of floats. • Scan the expression from left to right. • When encounter an operand or a float, push it on the stack. • When encounter an arithmetic operator, pop the top two numbers off the stack and use them as operands for the indicated operation. Push the resulting number back on the stack.
  • 5. • when you reach the end of the expression, the result of the calculation should be the sole item on the stack. Please show that that the program is working correctly by converting the following infix arithmetic expressions and then computing the obtained postfix arithmetic expressions: 6.5 * 6.5 - 4 * 1.5 * 1.44 # 3.1 * (2.5 + 4.7 * 1.6) + 8.6 # 70.0 - (10.5 + 6) / 0.5 + 18.2 # The following steps will convert an infix expression into a postfix expression: 1. Create an empty string stack called opStack for keeping operators. Create an empty string array called postfixEx for postfix expression. 2. read the infix expression left to right. 2.1. If the string is an operand, append it to the postfixEx array. 2.2. If the string is a left parenthesis, push it on the opStack. 2.3. If the string is a right parenthesis, pop the opStack, append each operator to the postfixEx array, until you see the corresponding left parenthesis, discard the pair of parentheses. 2.4. If the string is an operator, *, /, +, or -, first remove any operators already on the opStack that have higher or equal precedence and append them to the postfixEx array, then push the current operator on the opStack. 3. When the input infix expression has been completely processed, check the opstack, any operators still on the stack can be removed and appended to the end of the postfixEx array. The following steps will convert an infix expression into a postfix expression: 1. Create an empty string stack called opStack for keeping operators. Create an empty string array called postfixEx for postfix expression. 2. read the infix expression left to right. 2.1. If the string is an operand, append it to the postfixEx array. 2.2. If the string is a left parenthesis, push it on the opStack. 2.3. If the string is a right parenthesis, pop the opStack, append each operator to the postfixEx array, until you see the corresponding left parenthesis, discard the pair of parentheses. 2.4. If the string is an operator, *, /, +, or -, first remove any operators already on the opStack that have higher or equal precedence and append them to the postfixEx array, then push the current operator on the opStack.
  • 6. 3. When the input infix expression has been completely processed, check the opstack, any operators still on the stack can be removed and appended to the end of the postfixEx array. Solution #include #include #include #include using namespace std; int eval(int op1, int op2, char operate) { switch (operate) { case '*': return op2 * op1; case '/': return op2 / op1; case '+': return op2 + op1; case '-': return op2 - op1; default : return 0; } } int getpre(char ch) { switch (ch) { case '/': case '*': return 2; case '+': case '-': return 1; default : return 0; } } void in2pos(char infix[], char postfix[], int size) { stack s; int pre; int i = 0; int k = 0; char ch; while (i < size) { ch = infix[i];
  • 7. if (ch == '(') { s.push(ch); i++; continue; } if (ch == ')') { while (!s.empty() && s.top() != '(') { postfix[k++] = s.top(); s.pop(); } if (!s.empty()) { s.pop(); } i++; continue; } pre = getpre(ch); if (pre == 0) { postfix[k++] = ch; } else { if (s.empty()) { s.push(ch); } else { while (!s.empty() && s.top() != '(' && pre <= getpre(s.top())) { postfix[k++] = s.top(); s.pop(); } s.push(ch); } } i++; } while (!s.empty()) {
  • 8. postfix[k++] = s.top(); s.pop(); } postfix[k] = 0; } int evalpos(char postfix[], int size) { stack s; int i = 0; char ch; int val; while (i < size) { ch = postfix[i]; if (isdigit(ch)) { s.push(ch-'0'); } else { int op1 = s.top(); s.pop(); int op2 = s.top(); s.pop(); val = eval(op1, op2, ch); s.push(val); } i++; } return val; } int main() { const int max = 10; char infix[max] = {0}; int f; cout << "Please enter infix expression: " << endl; cin>>infix; int size = strlen(infix); char postfix[size]; in2pos(infix,postfix,size);
  • 9. cout<<" Infix Expression :: "<>f; return 0; }