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

首頁 > 編程 > C# > 正文

用C#實現插入排序

2023-05-16 12:36:07
字體:
來源:轉載
供稿:網友

導讀:本文介紹了使用C#實現插入法排序的算法

using System;
namespace InsertionSorter
{
       public class InsertionSorter 
       {
              public void Sort(int [] list)
              {
                       for(int i = 1; i < list.Length; i ++)
                      {
                                int t = list[i];
                                int j = i;
                                while(( j > 0)&&(list[j - 1] > t))
                                {
                                          list[j] = list[j - 1];
                                          -- j;
                                } 
                                list[j] = t;
                      } 
               } 
       }
 

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

上一篇:C#快速排序

下一篇:用C#實現冒泡法排序

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 襄汾县| 塔城市| 东乡县| 玛纳斯县| 土默特左旗| 红河县| 达州市| 将乐县| 萍乡市| 成安县| 玉龙| 临沭县| 锦州市| 宁强县| 兰溪市| 乐山市| 漠河县| 新巴尔虎右旗| 都安| 都匀市| 安岳县| 资阳市| 京山县| 项城市| 闽清县| 游戏| 宣武区| 五华县| 农安县| 天门市| 延寿县| 西盟| 洪泽县| 德令哈市| 南京市| 新巴尔虎右旗| 盘山县| 淳化县| 广元市| 上饶市| 五原县|