From the course: C# Hands-on Practice with Data-Structures

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

CoderPad Solution: Expression evaluator

CoderPad Solution: Expression evaluator - C# Tutorial

From the course: C# Hands-on Practice with Data-Structures

CoderPad Solution: Expression evaluator

Before diving into the implementation, let's walk through a few helper methods defined in CoderPad. The first method is IsNumber. This method takes in a token as a string and returns true or false based on whether it can be parsed into a double. The second method is IsOperator. This method checks if the given string matches one of our basic mathematical operators. The last method is PerformOperation. This method takes an operator and two operands and performs the corresponding mathematical operation. If the operator is invalid, it throws an exception. We can use these helper methods in our implementation in order to keep our code more concise. Now let's implement this method. We know that each operand comes before its operator. This means we need to keep track of each number until we see its operator. We can do this with the stack. We'll also use the stack to manage the intermediate results in the case of a string with multiple operations. Now we know each operand and operator is…

Contents