Assignment title: C++


You need to complete the following functions: a) function push() that pushes a value onto the stack b) function pop() that pops a value off the stack c) function stackTop() that returns the top value of the stack without popping the stack d) function isEmpty() that determines if the stack is empty e) function print() that prints the stack Task 2 Write a program that converts an ordinary infix arithmetic expression (assume a valid expression is entered) with single-digit integers such as (6 + 2) * 5 - 8 / 4 to a postfix expression. The postfix version of the preceding infix expression is Page 4 of 6 6 2 + 5 * 8 4 / - The program should read the infix expression and use modified versions of the stack functions implemented in this chapter to help create the postfix expression in character array postfix. The algorithm for creating a postfix expression is as follows: 1) Push a left parenthesis '(' onto the stack. 2) Append a right parenthesis ')' to the end of infix. 3) While the stack is not empty, read infix from left to right and do the following: If the current character in infix is a digit, copy it to the next element of postfix. If the current character in infix is a left parenthesis, push it onto the stack. If the current character in infix is an operator, Pop operators (if there are any) at the top of the stack while they have equal or higher precedence than the current operator, and insert the popped operators in postfix. Push the current character in infix onto the stack. If the current character in infix is a right parenthesis Pop operators from the top of the stack and insert them in postfix until a left parenthesis is at the top of the stack. Pop (and discard) the left parenthesis from the stack. The following arithmetic operations are allowed in an expression: + addition - subtraction * multiplication / division ^ exponentiation % modulus [Note: We assume left-to-right associativity for all operators for the purpose of this exercise.] The stack should be maintained with stack nodes, each containing a data member and a pointer to the next stack node. Task 3 Write the following functional capabilities: a) function convertToPostfix() that converts the infix expression to postfix notation void convertToPostfix( char * const infix, char * const postfix ) b) function isOperator() that determines whether char is an operator bool isOperator( char c ) c) function precedence() that determines whether the precedence of operator1 is less than, equal to or greater than the precedence of operator2 (the function true or false) bool precedence( char operator1, char operator2 ) Task 4 Create four infix arithmetic sample data of 10 integers including following operators +, -, *, /, ^ and %. Test your sample data and explain why they are good or bad sample data