コード例 #1
0
        /// <summary>
        /// The actual sort routine itself
        /// </summary>
        /// <returns>A refference to an instance of IntSortResults</returns>
        /// <param name="data">Input data</param>
        protected IntSortResults IntSortAsync(int[] data)
        {
            int i, j;
            int N = data.Length;

            var output = new IntSortResults();

            Array.Copy(data, output.UnsortedArray = new int[data.Length], data.Length);

            // Start a stopwatch so we can time this
            Stopwatch watch = new Stopwatch();

            watch.Reset();
            watch.Start();


            for (j = 1; j < N; j++)
            {
                for (i = j; i > 0 && data[i] < data[i - 1]; i--)
                {
                    Exchange(data, i, i - 1);
                }
            }

            // Now stop
            watch.Stop();

            output.Milliseconds = watch.ElapsedMilliseconds;
            output.SortedArray  = data;

            // Return the sorted array
            return(output);
        }
コード例 #2
0
        /// <summary>
        /// The actual sort routine itself
        /// </summary>
        /// <returns>A refference to an instance of IntSortResults</returns>
        /// <param name="data">Input data</param>
        protected IntSortResults IntSortAsync(int[] data)
        {
            int i;
            int N = data.Length;

            var output = new IntSortResults();

            Array.Copy(data, output.UnsortedArray = new int[data.Length], data.Length);

            // Start a stopwatch so we can time this
            Stopwatch watch = new Stopwatch();

            watch.Reset();
            watch.Start();

            for (i = 0; i < N - 1; i++)
            {
                int k = IntArrayMin(data, i);
                if (i != k)
                {
                    Exchange(data, i, k);
                }
            }

            // Now stop
            watch.Stop();

            output.Milliseconds = watch.ElapsedMilliseconds;
            output.SortedArray  = data;

            // Return the sorted array
            return(output);
        }
コード例 #3
0
ファイル: QuickSort.cs プロジェクト: markgr/DotNetCoreSwap
        /// <summary>
        /// The actual sort routine itself
        /// </summary>
        /// <returns>A refference to an instance of IntSortResults</returns>
        /// <param name="data">Input data</param>
        protected IntSortResults IntSortAsync(int[] data)
        {
            var output = new IntSortResults();

            Array.Copy(data, output.UnsortedArray = new int[data.Length], data.Length);

            // Start a stopwatch so we can time this
            Stopwatch watch = new Stopwatch();

            watch.Reset();
            watch.Start();


            IntArrayQuickSort(data, 0, data.Length - 1);

            // Now stop
            watch.Stop();

            output.Milliseconds = watch.ElapsedMilliseconds;
            output.SortedArray  = data;

            // Return the sorted array
            return(output);
        }