示例#1
0
        static void Main(string[] args)
        {
            BinaryTree <Student> tree = new BinaryTree <Student>();

            tree.Add(new Student("A", "A", new DateTime(10, 10, 10), 5));
            tree.Add(new Student("B", "A", new DateTime(11, 10, 10), 7));
            tree.Add(new Student("C", "A", new DateTime(12, 10, 10), 8));
            tree.Add(new Student("D", "A", new DateTime(13, 10, 10), 9));
            tree.Add(new Student("E", "A", new DateTime(14, 10, 10), 10));
            tree.Add(new Student("F", "A", new DateTime(15, 10, 10), 4));
            tree.Remove(new Student("A", "A", new DateTime(10, 10, 10), 5));
            Console.WriteLine();
            tree.Balance();
            tree.Serialize(@"D:\Тихон\Авы\Task5\BinaryTree\BinaryTree\bin\Debug\test.xml");
            BinaryTree <Student> newTree = new BinaryTree <Student>();
            bool res = newTree.Deserialize(@"D:\Тихон\Авы\Task5\BinaryTree\BinaryTree\bin\Debug\test.xml");

            Console.WriteLine(res);
            Console.ReadKey();
        }
示例#2
0
        static void Main(string[] args)
        {
            MyList <int>    intList    = new MyList <int>();
            MyList <string> stringList = new MyList <string>();

            Console.WriteLine("CREATE LIST");

            intList.Add(1);
            intList.Add(2);
            intList.Add(3);
            intList.Add(4);
            intList.Add(5);

            Console.WriteLine("Add 1, 2, 3, 4, 5 to intList:");

            foreach (var item in intList)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();

            intList.Remove(2);
            Console.WriteLine("Delete 2 from intList:");
            foreach (var item in intList)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();

            bool f = intList.Contains(3);

            Console.WriteLine(f == true ? "List contain 3" : "List doesn't contain 3");

            Console.WriteLine("Add 0 first in intList:");
            intList.AppendFirst(0);
            foreach (var item in intList)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();

            Console.WriteLine("Reverse 0 1 3 4 5:");
            foreach (var item in intList.Reverse())
            {
                Console.Write(item + " ");
            }

            Console.WriteLine();

            intList.Clear();
            Console.ReadKey();
            Console.Clear();


            Console.WriteLine("CREATE BINARY TREE:");


            var binaryTree = new BinaryTree <int>();

            binaryTree.Add(8);
            binaryTree.Add(3);
            binaryTree.Add(10);
            binaryTree.Add(1);
            binaryTree.Add(6);
            binaryTree.Add(4);
            binaryTree.Add(7);
            binaryTree.Add(14);
            binaryTree.Add(18);

            binaryTree.PrintTree();

            Console.WriteLine(new string('-', 40));
            Console.WriteLine("Delete 3 from tree:");
            binaryTree.Remove(3);
            binaryTree.PrintTree();

            Console.WriteLine(new string('-', 40));
            Console.WriteLine("Delete 8 from tree:");
            binaryTree.Remove(8);
            binaryTree.PrintTree();

            Console.WriteLine(new string('-', 40));

            if (binaryTree.FindNode(10) == null)
            {
                Console.WriteLine("DON'T FIND 10 in tree");
            }
            else
            {
                Console.WriteLine("FIND 10 in tree");
            }

            Console.ReadKey();
            Console.Clear();


            Console.WriteLine("SORT:");
            foreach (var item in MyInsertionSort.MySort(new[] { -5, 25, 25, 5, 0, -1, 0, -50 }))
            {
                Console.Write(item + " ");
            }

            Console.ReadKey();
        }