Ejemplo n.º 1
0
 public void run(long[] arr, long length, long value)
 {
     MergeSort(arr, 0, length - 1); //nlgn
     bbst = new BBST();
     bbst.CreateBBST(arr, 0, length - 1);
     search(value);//lg(n)
 }
Ejemplo n.º 2
0
        public void run(long[] arr, long length, long value)
        {
            if (length < 4)
            {
                Console.WriteLine("Sorry size of array must be greater than 3");
                return;
            }

            long first  = (length / 4) - 1;
            long second = (length / 2) - 1;
            long third  = (long)(length * 0.75) - 1;

            task1 = new Task(() =>
            {
                MergeSort(arr, 0, first);
            });

            task2 = new Task(() =>
            {
                MergeSort(arr, first + 1, second);
            });

            task3 = new Task(() =>
            {
                MergeSort(arr, second + 1, third);
            });

            task4 = new Task(() =>
            {
                MergeSort(arr, third + 1, length - 1);
            });

            Task task5 = new Task(() =>
            {
                bbst1 = new BBST();
                bbst1.CreateBBST(arr, 0, first);
            });

            Task task6 = new Task(() =>
            {
                bbst2 = new BBST();
                bbst2.CreateBBST(arr, first + 1, second);
            });

            Task task7 = new Task(() => {
                bbst3 = new BBST();
                bbst3.CreateBBST(arr, second + 1, third);
            });

            Task task8 = new Task(() => {
                bbst4 = new BBST();
                bbst4.CreateBBST(arr, third + 1, length - 1);
            });

            task1.Start();
            task2.Start();
            task3.Start();
            task4.Start();

            task1.Wait();
            task5.Start();

            task2.Wait();
            task6.Start();

            task3.Wait();
            task7.Start();

            task4.Wait();
            task8.Start();

            task5.Wait();
            task6.Wait();
            task7.Wait();
            task8.Wait();

//            bbst1.preOrder(bbst1.root);
//          Console.WriteLine();
//        bbst2.preOrder(bbst2.root);
//      Console.WriteLine();
//    bbst3.preOrder(bbst3.root);
//  Console.WriteLine();
// bbst4.preOrder(bbst4.root);
//Console.WriteLine();

            Search(value);
        }