会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
冬眠的蛤蟆
春醒,夏泳,秋思,冬眠…… MSN: "netflu"+"@"+"msn.com"
博客园
首页
新随笔
联系
订阅
管理
[排序] 冒泡排序
using
System;
using
System.Collections.Generic;
using
System.Text;
namespace
AlgoLibrary.Sort
{
/**/
///
<summary>
///
Summary description for BubbleSort.
///
</summary>
public
class
BubbleSort
{
private
int
[] _ary;
private
int
_count;
public
int
Count
{
get
{
return
_count; }
}
/**/
///
<summary>
///
默认构造函数
///
</summary>
///
<param name="ary"></param>
public
BubbleSort(
int
[] ary)
{
this
._ary
=
ary;
this
._count
=
_ary.Length;
}
/**/
///
<summary>
///
排序
///
</summary>
public
void
Sort()
{
int
temp
=
0
;
if
(_ary.Length
<=
1
)
{
return
;
}
else
if
(_ary.Length
==
2
)
{
if
(_ary[
0
]
>
_ary[
1
])
{
temp
=
_ary[
0
];
_ary[
0
]
=
_ary[
1
];
_ary[
1
]
=
temp;
return
;
}
}
for
(
int
i
=
0
; i
<
_ary.Length
-
1
; i
++
)
{
for
(
int
j
=
i
+
1
; j
<
_ary.Length; j
++
)
{
if
(_ary[i]
>
_ary[j])
{
temp
=
_ary[i];
_ary[i]
=
_ary[j];
_ary[j]
=
temp;
}
}
}
}
/**/
///
<summary>
///
重写基类 ToString() 方法
///
</summary>
///
<returns></returns>
public
override
string
ToString()
{
string
str
=
string
.Empty;
for
(
int
i
=
0
; i
<
_ary.Length; i
++
)
{
str
+=
_ary[i].ToString()
+
"
"
;
}
return
str;
}
}
//
class BubbleSort
}
//
namespace AlgoLibrary.Sort
posted @
2007-06-15 13:15
蛤蟆
阅读(
260
) 评论(
0
)
收藏
举报
刷新页面
返回顶部
公告