Created
October 26, 2016 02:21
-
-
Save toptensoftware/5da550148bb562f04dea9c12e2d8e8a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // NodeBinary for binary operations such as Add, Subtract etc... | |
| class NodeBinary : Node | |
| { | |
| // Constructor accepts the two nodes to be operated on and function | |
| // that performs the actual operation | |
| public NodeBinary(Node lhs, Node rhs, Func<double, double, double> op) | |
| { | |
| _lhs = lhs; | |
| _rhs = rhs; | |
| _op = op; | |
| } | |
| Node _lhs; // Left hand side of the operation | |
| Node _rhs; // Right hand side of the operation | |
| Func<double, double, double> _op; // The callback operator | |
| public override double Eval() | |
| { | |
| // Evaluate both sides | |
| var lhsVal = _lhs.Eval(); | |
| var rhsVal = _rhs.Eval(); | |
| // Evaluate and return | |
| var result = _op(lhsVal, rhsVal); | |
| return result; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment