求一排序算法
神马排序都可以
------解决方案--------------------------------------------------------
List<T>.Sort()
我啥也不懂,走错门进来的。
------解决方案--------------------------------------------------------
select X from tb order by X
------解决方案--------------------------------------------------------
冒泡? 快速排序?
------解决方案--------------------------------------------------------
private void btnRequest_Click(object sender, EventArgs e)
{
}
------解决方案--------------------------------------------------------
淡定。。
if
++
else
--
------解决方案--------------------------------------------------------
直接都用sort的说
------解决方案--------------------------------------------------------
冒泡排序:
- C# code
void BubbleSort(int[] values) { for (int i = 1; i < values.Length; i++) { for (int j = values.Length - 1; j >= i; j--) { if (values[j - 1] > values[j]) { int temp = values[j - 1]; values[j - 1] = values[j]; values[j] = temp; } } } }
------解决方案--------------------------------------------------------
冒泡排序
- C# code
private static void SortNum() { Int32[] array = new Int32[] { 1, 14, 8, 17, 3, 6 }; Console.WriteLine("冒泡排序前:"); for (int i = 0; i < array.Length; i++) { if (i == array.Length - 1) Console.Write(array[i]); else Console.Write(array[i] + ","); } int temp = 0; for (int i = 0; i < array.Length - 1; i++) { for (int j = 0; j < array.Length - 1 - i; j++) { if (array[j] > array[j + 1]) { temp = array[j]; array[j] = array[j + 1]; array[j + 1] = temp; } } } Console.WriteLine("\n"+"冒泡排序后:"); for (int i = 0; i < array.Length; i++) { if (i == array.Length - 1) Console.Write(array[i]); else Console.Write(array[i] + ","); } }
------解决方案--------------------------------------------------------
//1 冒泡排序法
public void Sort(int[] list)
{
long begintime = System.DateTime.Now.Second*1000+System.DateTime.Now.Millisecond;
WriteLine(begintime);
int j,temp;
j= 1;
while((j<list.Length))
{
for(int i=0;i<list.Length -j;i++)
{
if(list[i]<list[i+1])
{
temp = list[i];
list[i] = list[i+1];
list[i+1] = temp;
}
}
j++;
}
long endtime = System.DateTime.Now.Second*1000+System.DateTime.Now.Millisecond;
WriteLine(endtime);
WriteLine(endtime-begintime);
}
//2 选择排序法
public void SortChoice(int [] list)
{
long begintime = System.DateTime.Now.Millisecond;
int min;
for(int i=0;i<list.Length-1;i++)
{
min=i;
for(int j=i+1;j<list.Length;j++)
{
if(list[j]<list[min])
min=j;
}
int t=list[min];
list[min]=list[i];
list[i]=t;