- 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();
- }
- }
C# 冒泡排序
最新推荐文章于 2024-05-17 10:21:39 发布