sorting.cs

来自「VS.NET培训 vs.netppeixun.rar」· CS 代码 · 共 45 行

CS
45
字号
namespace Sort
{
    using System;

    public class Sorting{ 
        public Sorting()
		{
            // Class constructor is not used
        }
		
		/// <summary>
		/// Takes an array of doubles and sorts it using a bubblesort algorithm.
		/// It returns a new sorted array.
		/// </summary>
		/// <param name="original">An array of doubles to be sorted </param>
		
		public double[] BubbleSort(double[] original)
		{
			double temp;
			int x,y;
			double[] myarray;

			// Make a copy of the array
			myarray=(double[])original.Clone();

			//Step through the Array
			for (x=0; x<myarray.Length-1; x++)
			{
				for (y=0; y<myarray.Length-x-1; y++)
				{
					if (myarray[y] > myarray[y+1])
					{
						//swap the members
						temp=myarray[y];
						myarray[y]=myarray[y+1];
						myarray[y+1]=temp;
					}
				}
			}
			// Return the sorted array
			return myarray;
		}
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?