会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
学院派的驴
玄门非有闭,苦学当自开
博客园
首页
新随笔
联系
管理
订阅
(一)插入法排序
Code
1
void
SortByInsertion(
int
*
tobeSorted,
int
n)
2
{
3
for
(
int
j
=
1
;j
<
n;j
++
)
4
{
int
key
=
tobeSorted[j];
5
int
i
=
j
-
1
;
6
while
((i
>=
0
)
&&
(tobeSorted[i]
>
key))
7
{
8
tobeSorted[i
+
1
]
=
tobeSorted[i];
9
i
--
;
10
}
11
tobeSorted[i
+
1
]
=
key;
12
}
13
}
Code
1
#include
<
iostream
>
2
using
namespace
std;
3
int
main()
4
{
void
SortByInsertion(
int
*
tobeSorted,
int
n);
5
int
a[
6
]
=
{
5
,
2
,
4
,
6
,
1
,
3
};
6
for
(
int
i
=
0
;i
<
6
;i
++
)
7
{
8
cout
<<
a[i]
<<
"
;
"
;
9
}
10
cout
<<
endl;
11
SortByInsertion(a,
6
);
12
for
(
int
i
=
0
;i
<
6
;i
++
)
13
{
14
cout
<<
a[i]
<<
"
;
"
;
15
16
}
17
cout
<<
endl;
18
char
f;
19
cin
>>
f;
20
21
}
posted on
2009-08-09 09:54
finallyly
阅读(
503
) 评论(
0
)
收藏
举报
刷新页面
返回顶部
公告