模板天下 | 网页模板 | 学 院 | 源 码 | 书 籍 | 壁 纸 | 字 体 | JS脚本 | FLASH源码 | 软 件 | 矢 量 | 服务器软件 | 素 材 | 其 它 |
设为主页
加入收藏
联系站长
平面设计 | 网页制作 | 程序编写 | 数 据 库 | 媒体动画 | 网络冲浪 | 服务器相关 | 站长乐园 | 业界动态 |
当前在线
减治法:C#实现插入排序实例
2007-11-23 17:17:03  作者:模板天下收集整理  来源:未知 网友评论 0 条 论坛
  1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace InsertionSort
6{
7 class Program
8 {
9 static void Main(string[] args)
10 {
11 int[] a = new int[] { 2, 1, 4, 3 , 1, -4, 7, 11, 9,3,0};
12
13 Program p = new Program();
14
15 p.Sort(a);
16
17 for (int i = 0; i < a.Length; i++)
18 {
19 System.Console.WriteLine(a[i]);
20 }
21 }
22
23 public void Sort(int[] toBeSort)
24 {
25 for (int i = 1; i < toBeSort.Length; i++)
26 {
27 int v = toBeSort[i];
28
29 for (int j = i - 1; j > -1; j--)
30 {
31 if (v < toBeSort[j])
32 {
33 toBeSort[j + 1] = toBeSort[j];
34 toBeSort[j] = v;
35 }
36 }
37 }
38 }
39 }
40}
41
共分1页  [1] 

>> 相关文章
·减治法:C#实现插入排序实例

关于网站 | 客服中心 | 服务条款 | 合作伙伴 | 广告联系 | 本站历程 | 网站导航 | 发布资源 == 好的资源 大家共享

吉ICP备05000107号