示例#1
0
文件: Program.cs 项目: GarageInc/all
 //Перевод в массив
 static public void TreeToNewArray(Tree root, string[] mass, ref int max)
 {
     if (root == null) return;  // условие окончания - нет сыновей
     TreeToNewArray(root.left, mass, ref max);
     mass[max++] = root.value;
     TreeToNewArray(root.right, mass, ref max);
 }
示例#2
0
文件: Program.cs 项目: GarageInc/all
        //Добавление в дерево
        static public Tree Add(Tree root, string new_value)
        {
            if (root == null) // если нет сыновей - создаем новый элемент
            {
                root = new Tree();
                root.value = new_value;
                root.left = null;
                root.right = null;
                return root;
            }
            if (root.value.CompareTo(new_value) < 0)  // добавляем ветвь
            {
                root.right = Add(root.right, new_value);
            }
            else
            {
                root.left = Add(root.left, new_value);
            };

            return root;
        }