- usingSystem;
- namespaceInsertionSorter
- {
- publicclassInsertionSorter
- {
- publicvoidSort(int[]list)
- {
- for(inti=1;i<list.Length;i++)
- {
- intt=list[i];
- intj=i;
- while((j>0)&&(list[j-1]>t))
- {
- list[j]=list[j-1];
- --j;
- }
- list[j]=t;
- }
- }
- }
- publicclassMainClass
- {
- publicstaticvoidMain()
- {
- int[]iArrary=newint[]{1,13,3,6,10,55,98,2,87,12,34,75,33,47};
- InsertionSorterii=newInsertionSorter();
- ii.Sort(iArrary);
- for(intm=0;m<iArrary.Length;m++)
- {
- Console.Write("{0}",iArrary[m]);
- Console.WriteLine();
- }
- }
- }
- }
C#排序算法 之 插入排序
最新推荐文章于 2024-07-30 13:42:46 发布