会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
Haozes's Tech Space
人類的全部才能無非是時間和耐心的混合物
冒泡排序(C#数据结构学习九)
using
System;
using
System.Collections.Generic;
using
System.Text;
namespace
SoloDataStructure
{
class
MyBubbleSort
{
//
冒泡排序
static
void
BubbleSort(
int
[] arr)
{
int
n
=
arr.Length;
for
(
int
i
=
0
; i
<
n
-
1
; i
++
)
//
做n-1趟排序
{
bool
noswap
=
true
;
//
未交换标志
for
(
int
j
=
n
-
1
; j
>
i; j
--
)
{
if
(arr[j]
<
arr[j
-
1
])
{
//
swap记录
int
temp
=
arr[j];
arr[j]
=
arr[j
-
1
];
arr[j
-
1
]
=
temp;
noswap
=
false
;
}
}
if
(noswap)
return
;
}
}
static
void
Main(
string
[] args)
{
int
[] arr
=
new
int
[]
{
99
,
88
,
4
,
9
,
2
,
77
,
32
,
11
,
46
}
;
BubbleSort(arr);
Console.Write(
"
Data After BubbleSort:
"
);
foreach
(
int
i
in
arr)
{
Console.Write(i
+
"
,
"
);
}
Console.ReadLine();
}
}
}
posted on
2007-01-02 18:47
Haozes
阅读(
578
) 评论(
1
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
导航
首页
订阅
管理
公告