public NodeR(int Value) { Operation = ' '; this.Value = Value; Right = null; Left = null; }
public NodeR(char Operation, NodeR left, NodeR right) { this.Operation = Operation; this.Value = 0; this.Left = left; this.Right = right; }
public int Inter(string s) { PointError = new List <int>(); Root = null; FormTree(s); Root.GetValue(); if (PointError.Count != 0) { throw new InputError(); } return(Root.Value); }
NodeR Expression(string s, ref int Cur) { try { DelGaps(s, ref Cur); } catch (InputError) { PointError.Add(Cur); throw new InputError(); } NodeR A; try { A = ProcessNumber(s, ref Cur); } catch (InputError) { PointError.Add(Cur); A = new NodeR(0); } try { DelGaps(s, ref Cur); } catch (InputError) { return(A); } if (s[Cur] != '-' && s[Cur] != '+') { PointError.Add(Cur); Cur--; return(Expression(s, ref Cur)); } else { Cur--; return(new NodeR(s[Cur + 1], A, Expression(s, ref Cur))); //1+2+3+4 } }
void FormTree(string s) { int Cur = s.Length - 1; Root = Expression(s, ref Cur); }