コード例 #1
0
ファイル: turbosort.cs プロジェクト: dkandel/codechef
 static void Main(string[] args)
 {
     int input = int.Parse(Console.ReadLine());
     int[] inputs = new int[input];
     for (int i = 0; i < input; i++)
     {
         inputs[i] = int.Parse(Console.ReadLine());
     }
     //int[] res = new int[input3.Length];
     Sorting sort = new Sorting();
     var res = sort.MergeSort(inputs);
     foreach (int i in res)
     {
         Console.WriteLine(i);
     }
     Console.ReadLine();
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: jmarkova/ITCareer
        static void Main(string[] args)
        {
            // 0. Data Structure
            const int SIZE = 1000;

            int[] numbers = new int[SIZE];
            for (int i = 0; i < SIZE; i++)
            {
                numbers[i] = i;
            }

            // 1. Shifting = O(N)
            timer = new Stopwatch();
            timer.Start();
            Sorting.Shifting(numbers);
            timer.Stop();
            Console.WriteLine("Shifting ... ");
            // Console.WriteLine(string.Join(",", numbers));
            Console.WriteLine("Time = {0} ms\n", timer.Elapsed.TotalMilliseconds);

            // 2. SelectionSort = O(N^2)
            timer = new Stopwatch();
            timer.Start();
            Sorting.SelectionSort(numbers);
            timer.Stop();
            Console.WriteLine("SelectionSort ... ");
            // Console.WriteLine(string.Join(",", numbers));
            Console.WriteLine("Time = {0} ms\n", timer.Elapsed.TotalMilliseconds);

            // 3. BubbleSort = O(N^2)
            timer = new Stopwatch();
            timer.Start();
            Sorting.BubbleSort(numbers);
            timer.Stop();
            Console.WriteLine("BubbleSort ... ");
            // Console.WriteLine(string.Join(",", numbers));
            Console.WriteLine("Time = {0} ms\n", timer.Elapsed.TotalMilliseconds);

            // 4. InsertionSort = O(N^2)
            timer = new Stopwatch();
            timer.Start();
            Sorting.InsertionSort(numbers);
            timer.Stop();
            Console.WriteLine("InsertionSort ... ");
            // Console.WriteLine(string.Join(",", numbers));
            Console.WriteLine("Time = {0} ms\n", timer.Elapsed.TotalMilliseconds);

            // 5. MergeSort = O(N * log(N))
            timer = new Stopwatch();
            timer.Start();
            Sorting.MergeSort(numbers);
            timer.Stop();
            Console.WriteLine("MergeSort ... ");
            // Console.WriteLine(string.Join(",", numbers));
            Console.WriteLine("Time = {0} ms\n", timer.Elapsed.TotalMilliseconds);

            // 6. QuickSort = O(N * log(N))
            timer = new Stopwatch();
            timer.Start();
            Sorting.QuickSort(numbers);
            timer.Stop();
            Console.WriteLine("QuickSort ... ");
            // Console.WriteLine(string.Join(",", numbers));
            Console.WriteLine("Time = {0} ms\n", timer.Elapsed.TotalMilliseconds);
        }
コード例 #3
0
 public void InsertAtIndex(int index, string orderBy, Sorting direction)
 {
     _ordering.Insert(index, new SortingElement(orderBy, direction));
 }
コード例 #4
0
ファイル: Program.cs プロジェクト: JustinH-94/SortAlgorithms
 static void Main(string[] args)
 {
     Sorting sort = new Sorting();
 }
コード例 #5
0
 /** delegate method from ordering */
 public void Add(string orderBy, Sorting direction)
 {
     Add(new SortingElement(orderBy, direction));
 }