Exemple #1
0
        public bool TryLaodFromString(string st)
        {
            bool res = true;

            Clear();
            //Root = null;
            int pos = 0;

            Root = OneNode.NewNode(ref st, ref pos);
            //MessageBox.Show("In load tree "+ Root.ToString());
            while (pos < st.Length && st[pos] == ' ')
            {
                ++pos;
            }
            if (pos != st.Length || Root == null)
            {
                //MessageBox.Show("Can't");
                Clear();
                res = false;
            }
            return(res);
        }
Exemple #2
0
        public override bool LoadNodeFromString(ref string st, ref int pos)
        {
            bool res = true;

            if (pos >= st.Length)
            {
                res = false;
            }
            else
            if (st[pos] != '(')
            {
                res = false;
            }
            else
            {
                ++pos;
                while (pos < st.Length && st[pos] == ' ')
                {
                    ++pos;
                }
                left = OneNode.NewNode(ref st, ref pos);
                if (left == null)
                {
                    res = false;
                }
                else
                {
                    while (pos < st.Length && st[pos] == ' ')
                    {
                        ++pos;
                    }
                    int p = Array.IndexOf(Sings, st[pos]);
                    if (pos == st.Length || p == -1 || p == 4)
                    {
                        res = false;
                    }
                    else
                    {
                        sign = (Sign)p;
                        // MessageBox.Show("Sign in reading = " + st[pos] + " p = " + p+" si = "+sign);
                        ++pos;
                        right = OneNode.NewNode(ref st, ref pos);
                        if (right == null)
                        {
                            res = false;
                        }
                        else
                        {
                            while (pos < st.Length && st[pos] == ' ')
                            {
                                ++pos;
                            }
                            if (pos == st.Length || st[pos] != ')')
                            {
                                res = false;
                            }
                            else
                            {
                                ++pos;
                            }
                            //  MessageBox.Show("res = " + res);
                        }
                    }
                }
            }
            return(res);
        }