I’m trying to write a function, that goes within my main program, that will compare the precedence of operators being input by the user. The function would look for the following operators:
+, -, * , / with *, / having the highest precedence and +, - having the lowest precedence.
The operators with the lowest precedence go on the bottom of a stack while those with the highest precedence go on the top of the stack. So if a user types in +-*/, */+- should be displayed in the terminal.
Any ideas on how I should go about this?
Read all of the operators into a
std::string. Write a function with the following type:This function should return whether
lhshas higher precedence thanrhs.You can then use this function as the functor parameter of
std::sortto sort the operators by precedence.