Example #1
0
        public static void InterPolationSearchTest()
        {
            int    len   = 10;
            int    range = 1000;
            Random rnd   = new Random();

            int[] arr = new int[len];
            for (int i = 0; i < len; i++)
            {
                arr[i] = rnd.Next(range);
            }
            SimpleSort <int> .QuickSort(ref arr, len);

            foreach (int i in arr)
            {
                Console.Write("{0} ", i);
            }
            while (true)
            {
                Console.WriteLine("\n\n Search : ");
                int key;

                try { key = int.Parse(Console.ReadLine()); }
                catch { break; }

                Console.WriteLine("\nOk. Search {0}.", key);
                InterpolationSearch its = new InterpolationSearch(arr, key, (idx) => Console.WriteLine("The Index is {0}.", idx));
                its.Work();
                Console.WriteLine("-------------");
            }
        }
Example #2
0
        public static void SortTest1()
        {
            int len = 10;

            int[]  arr = new int[len];
            Random rnd = new Random();

            for (int i = 0; i < len; i++)
            {
                Console.WriteLine(arr[i] = rnd.Next(20));
            }
            SimpleSort <int> .BubbleSort(ref arr, len);

            foreach (int i in arr)
            {
                Console.WriteLine(i);
            }
            Console.WriteLine();
            for (int i = 0; i < len; i++)
            {
                Console.WriteLine(arr[i] = rnd.Next(20));
            }
            SimpleSort <int> .SelectionSort(ref arr, len);

            foreach (int i in arr)
            {
                Console.WriteLine(i);
            }
        }
Example #3
0
        public static void SwapTest()
        {
            int a = 10;
            int b = 20;

            int[] arr = new int[3] {
                1, 2, 3
            };
            SimpleSort <int> .Swap(ref a, ref b);

            SimpleSort <int> .Swap(ref arr[0], ref arr[2]);

            Console.WriteLine("{0}, {1}", a, b);
            Console.WriteLine("{0}, {1}, {2}", arr[0], arr[1], arr[2]);
        }
Example #4
0
        public static void HPSRT_Test()
        {
            int len = 10;

            int[]  arr = new int[len];
            Random rnd = new Random();

            for (int i = 0; i < len; i++)
            {
                arr[i] = rnd.Next(20); Console.WriteLine(arr[i]);
            }
            Console.WriteLine();
            SimpleSort <int> .HeapSort(ref arr, len);

            foreach (int i in arr)
            {
                Console.WriteLine(i);
            }
        }