国产探花免费观看_亚洲丰满少妇自慰呻吟_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();
                   }
          }
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宁乡县| 盐津县| 卢湾区| 鲁山县| 英吉沙县| 新乐市| 商城县| 资溪县| 永济市| 襄城县| 凤城市| 寻甸| 台州市| 南通市| 安福县| 河东区| 波密县| 西宁市| 湛江市| 信阳市| 望奎县| 揭西县| 社会| 自治县| 阿勒泰市| 娱乐| 延庆县| 青铜峡市| 寿光市| 全椒县| 鄢陵县| 五指山市| 简阳市| 青铜峡市| 云梦县| 霞浦县| 新河县| 呼和浩特市| 苍山县| 马边| 广灵县|