- usingSystem;
- namespaceBubbleSorter
- {
- publicclassBubbleSorter
- {
- publicvoidSort(int[]list)
- {
- inti,j,temp;
- booldone=false;
- j=1;
- while((j<list.Length)&&(!done))
- {
- done=true;
- for(i=0;i<list.Length-j;i++)
- {
- if(list[i]>list[i+1])
- {
- done=false;
- temp=list[i];
- list[i]=list[i+1];
- list[i+1]=temp;
- }
- }
- j++;
- }
- }
- }
- publicclassMainClass
- {
- publicstaticvoidMain()
- {
- int[]iArrary=newint[]{1,5,13,6,10,55,99,2,87,12,34,75,33,47};
- BubbleSortersh=newBubbleSorter();
- sh.Sort(iArrary);
- for(intm=0;m<iArrary.Length;m++)
- {
- Console.Write("{0}",iArrary[m]);
- Console.WriteLine();
- }
- }
- }
- }
C#排序算法 之 冒泡排序
最新推荐文章于 2024-11-03 22:21:51 发布