Beispiel #1
0
 public NodeR(int Value)
 {
     Operation  = ' ';
     this.Value = Value;
     Right      = null;
     Left       = null;
 }
Beispiel #2
0
 public NodeR(char Operation, NodeR left, NodeR right)
 {
     this.Operation = Operation;
     this.Value     = 0;
     this.Left      = left;
     this.Right     = right;
 }
Beispiel #3
0
 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);
 }
Beispiel #4
0
        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
            }
        }
Beispiel #5
0
        void FormTree(string s)
        {
            int Cur = s.Length - 1;

            Root = Expression(s, ref Cur);
        }