it is reverse POLISH notation :nerdy-face:
This commit is contained in:
@@ -144,7 +144,7 @@
|
|||||||
{
|
{
|
||||||
if (currentOperand != "") equation.Add(new Token(Token.TokenType.Operand, currentOperand));
|
if (currentOperand != "") equation.Add(new Token(Token.TokenType.Operand, currentOperand));
|
||||||
buttonEquals.Text = "#";
|
buttonEquals.Text = "#";
|
||||||
currentOperand = ReverseNotationSolver.Solve(equation);
|
currentOperand = ReversePolishNotationSolver.Solve(equation);
|
||||||
UpdateLabels();
|
UpdateLabels();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
namespace Lunar.Evil_Calculator
|
namespace Lunar.Evil_Calculator
|
||||||
{
|
{
|
||||||
internal static class ReverseNotationSolver
|
internal static class ReversePolishNotationSolver
|
||||||
{
|
{
|
||||||
private static List<Token> ToReverseNotation(List<Token> equation)
|
private static List<Token> ToReversePolishNotation(List<Token> equation)
|
||||||
{
|
{
|
||||||
List<Token> reversedEquation = new List<Token>();
|
List<Token> reversedEquation = new List<Token>();
|
||||||
Stack<Token> operators = new Stack<Token>();
|
Stack<Token> operators = new Stack<Token>();
|
||||||
@@ -47,7 +47,7 @@
|
|||||||
|
|
||||||
public static string Solve(List<Token> originalEquation)
|
public static string Solve(List<Token> originalEquation)
|
||||||
{
|
{
|
||||||
List<Token> reversedEquation = ToReverseNotation(originalEquation);
|
List<Token> reversedEquation = ToReversePolishNotation(originalEquation);
|
||||||
Stack<Token> stack = new Stack<Token>();
|
Stack<Token> stack = new Stack<Token>();
|
||||||
foreach (Token token in reversedEquation)
|
foreach (Token token in reversedEquation)
|
||||||
{
|
{
|
||||||
Reference in New Issue
Block a user