Exemplo n.º 1
0
        static void Main(string[] args)
        {
            //int[] arr = { 1, 5, 3, 9, 8, 11, 15, 0 };
            //var sw = Stopwatch.StartNew();
            //QuickSort(arr, 0, arr.Length-1);
            ////bubbleSort(arr, 8);
            ////Console.WriteLine(CountVowels("ádasdasgfafhiu"));
            //for (int i = 0; i < arr.Length; i++)
            //{
            //    Console.WriteLine(arr[i]);
            //}

            ////Console.WriteLine(Max(arr).ToString());
            ////Console.WriteLine(Min(arr).ToString());
            //Console.WriteLine(Math.Round(PerimeterRectangle(7.2,5.4),3));

            //Console.WriteLine(Math.Round(PerimeterCircle(5.4),3));

            //Console.WriteLine("Phan tu co gia tri "+11+" o vi tri : "+BinarySearch(arr,0,7,11)??"Không tìm thấy");

            //sw.Stop();
            //Console.WriteLine("Time elapsed: " + sw.Elapsed);



            // Binary search tree

            List <int> listAdd = new List <int> {
                70, 49, 37, 22, 40, 54, 84, 78, 76, 80, 85
            };

            BinaryTree tree = new BinaryTree();

            Console.WriteLine("Them cac gia tri vao cay nhi phan:");
            Random random = new Random();

            //while(true)
            //{
            Console.WriteLine("Nhap gia tri node can them vao cay (Nhap 0 de thoat ) :");

            for (int i = 0; i < listAdd.Count; i++)
            {
                tree.InsertNode(listAdd[i]);
            }

            //int key = int.Parse(Console.ReadLine());
            //if (key == 0)
            //    break;
            //tree.InsertNode(key);
            //}

            Console.WriteLine("\n\nDuyet tien tu  Pre Order:");
            tree.PreOrder(tree.root);
            Console.WriteLine("\n\nDuyet trung tu In Order:");
            tree.InOrder(tree.root);
            Console.WriteLine("\n\nDuyet hau tu Post Order:");
            tree.PostOrder(tree.root);
            Console.Write("\n\nNhap khoa can tim kiem:");
            int  keysearch = int.Parse(Console.ReadLine());
            bool result    = tree.Search(tree.root, keysearch);

            if (result)
            {
                Console.WriteLine("Tim thay {0} trong cay nhi phan tim kiem", keysearch);
            }
            else
            {
                Console.WriteLine("Khong tim thay {0} trong cay nhi phan tim kiem", keysearch);
            }
        }