C# 冒泡排序
来源:互联网 发布:淘宝上买电信卡 编辑:程序博客网 时间:2024/05/03 13:20
- using System;
- public class BubbleSort
- {
- public void Sort(int[] list)
- {
- int temp;
- for(int i=0;i<list.Length-1;i++)
- {
- for(int j=i+1;j<list.Lenght;j++)
- {
- if (list[j]<list[i])
- {
- temp=list[j];
- list[j]=list[i];
- list[i]=temp;
- }
- }
- }
- }
-
- public static void Main(string[] arg)
- {
- int testArray=new int[]{1,11,3,32,22,12,33,55};
- BubbleSort bs=new BubbleSort();
- bs.Sort(testArray);
- for(int i=0;i<testArray.Length;i++)
- {
- Console.WriteLine("{0}",testArray[i]);
- }
- Console.ReadKey();
- }
- }