-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
80 lines (77 loc) · 3.59 KB
/
Program.cs
File metadata and controls
80 lines (77 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tree
{
class Program
{
static void Main(string[] args)
{
var rnd = new Random();
TreeFunctions tree = new TreeFunctions();
//
Console.Write("Введите целочисленное значение: ");
int userX = Convert.ToInt32(System.Console.ReadLine());
userX = Math.Abs(userX);
System.Console.WriteLine();
do
{// случайные значения
tree.DoSomeAdd(rnd.Next(userX) + 1);
userX--;
} while (userX != 0);
// количество уровней древа
int i = TreeFunctions.height(tree.Root);
// Вывод результатов
ShowMeNodes(tree.Root, i);
// я эксперементально проверил, что двойка генерируется случайным образом всегда при уровне больше 3
// если такого не случилось перезапустите программу
Console.WriteLine("Удаляем 2 (двойку), где бы она не находилась.");
//********************
tree.deleteKey(2);
//********************
System.Console.WriteLine("Смотрим результат.");
ShowMeNodes(tree.Root, i);
Console.Write("Введите целочисленное значение для удаления (Не корень и не последний уровень!): ");
userX = Convert.ToInt32(System.Console.ReadLine());
userX = Math.Abs(userX);
tree.deleteKey(userX);
System.Console.WriteLine("Смотрим окончательный результат.");
ShowMeNodes(tree.Root, i);
System.Console.WriteLine();
// красиво сделать так мне и не удалось :(
Console.Write("Выводить визуализацию древа ? ");
Console.Write(" [ Да - 1 / Нет - 2] " );
userX = Convert.ToInt32(System.Console.ReadLine());
System.Console.WriteLine();
if ( userX == 1 )
{
Console.Clear();
System.Console.WriteLine("| 1 Lvl | 2 Lvl | 3 Lvl | 4 Lvl | 5 Lvl | 6 Lvl | 7 Lvl | 8 Lvl | 9 Lvl | ");
TreeFunctions.printTree(tree.Root);
}
Console.ReadLine();
}
public static void ShowMeNodes(Node node,int i)
{
System.Console.WriteLine("Все значения в дереве по порядку: ");
TreeFunctions.sorted_level_order(node);
System.Console.WriteLine();
System.Console.WriteLine();
System.Console.WriteLine("Breadth - first search finds nodes on each level.");
do
{
System.Console.WriteLine();
System.Console.Write("Nodes on " + i + " level: ");
TreeFunctions.printGivenLevel(node, i);
System.Console.WriteLine();
i--;
} while (i != 0);
System.Console.WriteLine();
System.Console.Write("Depth-first search finds this deepest node - ");
System.Console.WriteLine(TreeFunctions.deepestNode(node));
System.Console.WriteLine();
}
}
}