麻烦写一下这个程序,这是一个stacks in c++

Lab Objectives.
In this lab, you will practice what you had learned in the Stack slides

Description of the Problem:
Please also include your UML design. You will use your StackArrayBag and LinkedArrayBag classes here.

Please write a program that evaluates a postfix expression (assume it is valid) such as6 2 + 5 * 8 4 / -

The program should read a postfix expression consisting of digits and operators into a character array. Using modified versions of the stack functions implemented earlier in this chapter, the program should scan the expression and evaluate it. The algorithm is as follows:

  • 1) Append the null character ('\0') to the end of the postfix expression. When the null character is encountered, no further processing is necessary.
  • 2) While '\0' has not been encountered, read the expression from left to right. If the current character is a digit,

Push its integer value onto the stack (the integer value of a digit character is its value in the computer’s character set minus the value of '0' in the computer’s character set).
Otherwise, if the current character is an operator,
Pop the two top elements of the stack into variables x and y. Calculate y operator x.
Push the result of the calculation onto the stack.

  • 3) When the null character is encountered in the expression, pop the top value of the stack. This is the result of the postfix expression.

[Note: In Step 2 above, if the operator is '/', the top of the stack is 2 and the next element in the stack is 8, then pop 2 into x, pop 8 into y, evaluate 8 / 2 and push the result, 4, back onto the stack. This note also applies to operator '–'.] The arithmetic operations allowed in an expression are

  • 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 that contain an int data member and a pointer to the next stack node. You may want to provide the following functional capabilities:

a) function evaluatePostfixExpression that evaluates the postfix expression
b) function calculate that evaluates the expression op1 operator op2
c) function push that pushes a value onto the stack
d) function pop that pops a value off the stack
e) function isEmpty that determines if the stack is empty
f) function printStack that prints the stack

图片说明

怎么重复发了2个?两个问题有区别么?我回答在 https://ask.csdn.net/questions/899048 里了。