zoukankan
html css js c++ java
冒泡排序(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();
}
}
}
查看全文
相关阅读:
动态规划之解决01背包问题 【转载】
暴力搜索解0-1背包问题 【转载】
回溯法之地图着色
贪心算法之最小生成树
贪心算法之最短路径
HMM隐马尔科夫模型
变分贝叶斯
Leetcode好的微博
HMM隐马尔科夫模型浅析
向量的协方差矩阵浅析
原文地址:https://www.cnblogs.com/solo/p/610138.html
最新文章
iOS开发之IBInspectable及IB_DESIGNABLE
iOS10之UserNotifications初见
iOS之copy、strong使用,block特性
[] __nw_connection
ios开发之手电筒使用补充
设计模式
linux 命令
ASP.NET-AD(ActiveDirectory)用户验证
.net里如何判断字符长度
LINQ--- MAX()函数 group by
热门文章
linq
座右铭
获取当前URL
javascript RadioButtonList 選択値
C# 后台生成javascript
IT笔试输入输出处理总结
C++笔试输入注意事项
IT互联网公司的笔试的输入输出
Google Protocol Buffer 的使用和原理 【转载】
消息队列之ZeroMQ(C++)
Copyright © 2011-2022 走看看