国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

用C#實現冒泡法排序

2023-05-16 12:36:07
字體:
來源:轉載
供稿:網友
導讀:本文給出了使用C#進行冒泡法排序的源代碼

using System;
namespace BubbleSorter
{
              public class BubbleSorter
              {
                        public void Sort(int [] list)
                       {
                               int i, j, temp;
                               bool done = 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 ++; 
                                } 
                        }
            }

         public class MainClass
         {
                   public static void Main( )
                   { 
                                int[] iArrary=new int[]{1,5,13,6,10,55,99,2,87,12,34,75,33,47};
                                BubbleSorter xyt=new BubbleSorter();
                                xyt.Sort(iArrary);
                                for(int m = 0;m < iArrary.Length; m ++)
                                         Console.Write("{0} ",iArrary[m]);
                               Console.WriteLine();
                   }
          }
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 遂平县| 盘山县| 永寿县| 南宫市| 南丰县| 长沙市| 张家川| 亚东县| 都昌县| 米林县| 景宁| 博兴县| 望城县| 麻城市| 邻水| 谢通门县| 慈利县| 建始县| 湟源县| 黔江区| 嘉祥县| 娱乐| 来凤县| 邛崃市| 游戏| 双城市| 兴山县| 密云县| 汕尾市| 兴业县| 哈巴河县| 泽州县| 崇文区| 峨边| 镇坪县| 衡阳县| 新安县| 灵寿县| 长沙县| 柳江县| 绵阳市|