会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
Haozes's Tech Space
人類的全部才能無非是時間和耐心的混合物
插入排序(C#数据结构学习七)
using
System;
using
System.Collections.Generic;
using
System.Text;
namespace
SoloDataStructure
{
class
MyInsertSort
{
//
插入排序
//
这个简单不多注释
static
void
InsertSort (
int
[] array)
{
//
递增排序
int
temp;
int
i, j,n;
n
=
array.Length;
for
( i
=
1
; i
<
n; i
++
)
{
temp
=
array[i];
//
设置监哨
for
( j
=
i; j
>
0
; j
--
)
if
( temp
<
array[j
-
1
])
array[j]
=
array[j
-
1
];
//
记录后移
else
break
;
array[j]
=
temp;
//
插入array[i];
}
}
static
void
Main(
string
[] args)
{
int
[] arr
=
new
int
[]
{
49
,
38
,
65
,
97
,
76
,
13
,
27
,
49
}
;
Console.Write(
"
原数组数据顺序:
"
);
foreach
(
int
i
in
arr)
{
Console.Write(i
+
"
.
"
);
}
InsertSort(arr);
Console.Write(
"
\n插入排序后数组数据顺序:
"
);
for
(
int
i
=
0
; i
<
arr.Length; i
++
)
Console.Write(arr[i]
+
"
.
"
);
Console.ReadLine();
}
}
}
posted on
2007-01-01 20:37
Haozes
阅读(
657
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
导航
首页
订阅
管理
公告