会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
不凡
思想创造世界
网上看到的排序源码, 准备面试的朋友可以看看
c++写的选择排序, 冒泡排序
//
选择排序
template
<
typename T
>
void
SelectionSort(T arr[],
int
n)
{
int
smallIndex;
int
pass,j;
T temp;
for
(pass
=
0
;pass
<
n
-
1
;pass
++
)
{
smallIndex
=
pass;
for
(j
=
pass
+
1
;j
<
n;j
++
)
{
if
(arr[j]
<
arr[smallIndex])
smallIndex
=
j;
}
if
(smallIndex
!=
pass)
{
temp
=
arr[pass];
arr[pass]
=
arr[smallIndex];
arr[smallIndex]
=
temp;
}
}
}
//
冒泡排序
template
<
typename T
>
int
bubbleSortEx(T arr[],
int
n)
{
int
i,pass;
T temp;
for
(pass
=
0
;pass
<
n;pass
++
)
{
for
(i
=
0
;i
<
n
-
pass;i
++
)
{
if
(arr[i]
>
arr[i
+
1
])
{
temp
=
arr[i];
arr[i]
=
arr[i
+
1
];
arr[i
+
1
]
=
temp;
}
}
}
return
pass;
}
posted on
2005-05-11 10:48
hunter_gio
阅读(
511
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
导航
博客园
首页
新随笔
联系
订阅
管理
公告