Exemple #1
0
        private void BuildTree(string s)
        {
            if (Regex.IsMatch(s, "^([0-9]+,)*[0-9]+$"))
            {
                tree = BuildIntTree();
            }
            else if (Regex.IsMatch(s, "^([A-Za-z]+,)*[A-Za-z]+$"))
            {
                tree = BuildStringTree();
            }
            else
            {
                MessageBox.Show("Некорректный формат списка узлов дерева.");
                return;
            }

            textBoxPreOrder.Text = tree.PreOrderTraverse();
            textBoxInOrder.Text = tree.InOrderTraverse();
            textBoxPostOrder.Text = tree.PostOrderTraverse();

            tree.ComputeNodePositions();

            textBoxThreadedInOrder.Text = tree.MakeInOrderRightThreaded()
                .ThreadedTraverse();
        }
Exemple #2
0
        private BinaryTree BuildIntTree()
        {
            tree = new BinaryTree<int>();

            foreach (var item in textBox1.Text.Split(','))
            {
                ((BinaryTree<int>)tree).Insert(Convert.ToInt32(item));
            }

            return tree;
        }
Exemple #3
0
        private BinaryTree BuildStringTree()
        {
            tree = new BinaryTree<string>();

            foreach (var item in textBox1.Text.Split(','))
            {
                ((BinaryTree<string>)tree).Insert(item);
            }

            return tree;
        }
Exemple #4
0
 private void button2_Click(object sender, EventArgs e)
 {
     tree = null;
     BuildTree(textBox1.Text);
     panel1.Invalidate();
 }
Exemple #5
0
 private void textBox1_TextChanged(object sender, EventArgs e)
 {
     tree = null;
     panel1.Invalidate();
     textBoxPreOrder.Clear();
     textBoxInOrder.Clear();
     textBoxPostOrder.Clear();
     textBoxThreadedInOrder.Clear();
 }
Exemple #6
0
        private void BuildSample(string s)
        {
            textBox1.Text = s;
            tree = null;
            panel1.Invalidate();
            textBoxPreOrder.Clear();
            textBoxInOrder.Clear();
            textBoxPostOrder.Clear();
            textBoxThreadedInOrder.Clear();

            BuildTree(s);
        }