当前位置:网站首页>bubble sort
bubble sort
2022-06-23 03:45:00 【@Landscape post yuan】
The structures and functions used in sorting
# define MAXSIZE 10
typedef struct {
/* use On save Store want row order Count Group , r[0] use do whistle The soldiers or In the when change The amount */
int r[ MAXSIZE + 1];
/* use On remember record along order surface Of Long degree */
int length ;
} SqList ;
/* hand over in L in Count Group r Of Next mark by i and j Of value */
void swap ( SqList *L, int i, int j){
int temp = L- >r[i];
L->r[i] = L- >r[j];
L->r[j] = temp ;
}Bubble sort primary version
/* Yes along order surface L do hand over in row order ( Risk bubble row order first level edition ) */
void BubbleSort0 ( SqList *L){
int i, j;
for (i = 1; i < L- > length ; i++) {
for (j = i + 1; j <= L- > length ; j++) {
if (L- >r[i] > L->r[j]) {
/* hand over in L- >r[i] And L->r[j] Of value */
swap (L, i, j) ;
}
}
}
}Bubble sort classic version —— Two by two

/* Yes along order surface L do Risk bubble row order */
void BubbleSort ( SqList *L){
int i, j;
for (i = 1; i < L- > length ; i++) {
/* notes It means j yes from after Go to front Follow Ring */
for (j = L-> length - 1; j >= i;j - -) {
/* if front person Big On after person ( notes It means this in And On One count Law Bad different ) */
if (L- >r[j] > L->r[j + 1]) {
/* hand over in L- >r[j] And L->r[j+1] Of value */
swap (L, j, j + 1) ;
}
}
}
}Bubble sort upgrade version
If the embedded inner loop does not need to be swapped , So it means that the initial values of the following sequence are arranged
void BubbleSort2 ( SqList *L){
int i, j;
Status flag = TRUE ; /* flag use Come on do by mark remember */
/* if flag by true say bright Yes too Count According to the hand over in , no be stop stop Follow Ring */
for (i = 1; i < L- > length && flag ; i++) {
flag = FALSE ;/* first beginning by false */
for (j = L-> length - 1; j >= i; j - -) {
if (L- >r[j] > L->r[j + 1]) {
/* hand over in L- >r[j] And L->r[j+1] Of value */
swap (L, j, j + 1) ;
/* Such as fruit Yes Count According to the hand over in , be flag by true */
flag = TRUE ;
}
}
}
}
边栏推荐
- 页面导出excel的三种方式
- mysql 数据恢复 (.ibdata1, bin log)
- Easygbs service is killed because the user redis is infected with the mining virus process. How to solve and prevent it?
- Brief introduction to arm architecture
- How to realize data transaction
- Nature: correlation between oscillatory signals and gene expression supporting human episodic memory coding
- An implementation of warning bombing
- Analysis on development history, industrial chain, output and enterprise layout of medical polypropylene in China in 2020 [figure]
- 【LeetCode】23. Merge K ascending linked lists
- Analysis of China's integrated circuit industry chain in 2021: huge downstream market demand [figure]
猜你喜欢

innodb_ruby 视角下 MySQL 记录增删改

JS Part 4

Talk about memory model and memory order

The first batch of job hunting after 00: don't misread their "different"

Google Earth Engine(GEE)——长时间序列逐月VCI数据提取分析和面积计算(墨西哥为例)

【机器学习】 吴恩达机器学习作业 ex2逻辑回归 Matlab实现

centos7 安装 MySQL 及配置 innodb_ruby

Analysis on the development of China's graphene industry chain in 2021: with the support of energy conservation and environmental protection policies, the scale of graphene industry will continue to e

【owt】owt-client-native-p2p-e2e-test vs2017构建2 :测试单元构建及运行

直接插入排序
随机推荐
RTOS system selection for charging point software design
Get method of fetch request and data of formdata type submitted by post
Engineer culture: should the company buy genuine software
Google Earth engine (GEE) - long time series monthly VCI data extraction, analysis and area calculation (Mexico as an example)
Tencent released the global DDoS threat report in 2021: DDoS threat has become the preferred extortion method for criminal gangs
Analysis on the development of China's graphene industry chain in 2021: with the support of energy conservation and environmental protection policies, the scale of graphene industry will continue to e
[leetcode] flip linked list II
Tcapulusdb Jun · industry news collection (III)
Parsing the implementation of easygbs compatible token as parameter passing
Analysis on the development of duty-free industry in Hainan Province in 2021: the implementation of the new policy makes the duty-free market in Hainan more "prosperous" [figure]
An implementation of warning bombing
【二分】leetcode1011. Capacity To Ship Packages Within D Days
MySQL common instructions
What are the advantages of the completely free and open source flutter? How to learn about flutter?
【LeetCode】179. 最大数
Swiftui component encyclopedia creating animated 3D card scrolling effects using Scrollview and geometryreader
TRTC zero foundation -- Video subscription on the code
[metauniverse 7ai rope skipping] how is this app light application realized? What are the application scenarios?
【owt】owt-client-native-p2p-e2e-test vs2017构建 4 : 第三方库的构建及链接p2pmfc.exe
WordPress modifying fixed links and pseudo statics