会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
易懂
简单就是好!
博客园
首页
新随笔
联系
管理
订阅
C#的数据结构
今天看了C的数据结构,无聊写了一些C#的数据结构算法.
class
Program
{
static
void
Main(
string
[] args)
{
int
[] list
=
new
int
[]
{
10
,
9
,
8
,
7
,
6
,
5
,
4
,
3
,
2
,
1
}
;
bubbleSort(list);
}
//
冒泡算法
public
static
void
bubbleSort(
int
[] list)
{
int
temp;
int
count
=
0
;
for
(
int
j
=
list.Length; j
>
0
;j
--
)
//
外循环
{
for
(
int
i
=
0
; i
<
j
-
1
; i
++
)
//
内循环
{
if
(list[i]
>
list[i
+
1
])
{
temp
=
list[i];
list[i]
=
list[i
+
1
];
list[i
+
1
]
=
temp;
count
++
;
}
}
Console.WriteLine(
"
list值:
"
+
list[j
-
1
].ToString ());
}
Console.WriteLine(count);
Console.ReadLine();
}
//
选择算法
public
static
void
selectSort(
int
[] list)
{
int
temp
=
0
;
int
count
=
0
;
for
(
int
j
=
0
; j
<
list.Length ; j
++
)
{
int
MinNumber
=
list[j];
int
Index
=
j;
for
(
int
i
=
j; i
<
list.Length; i
++
)
//
找最小值
{
if
(MinNumber
>
list[i])
{
MinNumber
=
list[i];
Index
=
i;
count
++
;
}
}
temp
=
list[Index];
list[Index]
=
list[j];
list[j]
=
temp;
Console.WriteLine(
"
list值:
"
+
list[j]);
}
Console.WriteLine(count);
Console.ReadLine();
}
}
posted @
2008-04-05 17:39
啊文
阅读(
168
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告