当前位置:网站首页>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 ;
}
}
}
}
边栏推荐
- Even if you don't learn gradle, these common development operations are worth mastering
- 【owt】owt-client-native-p2p-e2e-test vs2017构建2 :测试单元构建及运行
- China's economy has entered the stage of "the third mock examination coexisting", and JD and Shopify have jointly arranged global DTC
- Swiftui component encyclopedia creating animated 3D card scrolling effects using Scrollview and geometryreader
- Insérer le tri directement
- Goframe framework: quick creation of static file download web service
- innodb_ruby 视角下 MySQL 记录增删改
- TRTC setaudioroute invalid problem
- Customization of openfeign
- D overloading nested functions
猜你喜欢

R tree of search tree

Jmeter- (V) simulated user concurrent login for interface test

HAProxy的编译安装及全局配置段说明

innodb_ruby 视角下 MySQL 记录增删改

线上MySQL的自增id用尽怎么办?

Hierarchical attention graph convolution network for interpretable recommendation based on knowledge graph

mysql常用指令

Banknext microservice: a case study

【owt】owt-client-native-p2p-e2e-test vs2017构建 4 : 第三方库的构建及链接p2pmfc.exe
![[OWT] OWT client native P2P E2E test vs2017 build 2: test unit construction and operation](/img/b0/4ea8069a88ce19ca7dbfa67ac9fcba.png)
[OWT] OWT client native P2P E2E test vs2017 build 2: test unit construction and operation
随机推荐
Decentralized networks are not decentralized
D overloading nested functions
mysql常用指令
[leetcode] sum of two numbers II
Frequent actions to expand the scale of new energy industry Guangzhou plans to invest 1.4 billion in photovoltaic power generation projects
Goframe framework: log configuration management
1-1 introduction to VMWare
How to make distribution box label
The new version of Kali switches the highest account
数据交易怎样实现
Detailed discussion on modular architecture design of MCU firmware
【LeetCode】两数之和II
How to implement collection sorting?
Enterprise official website applet building tutorial
How to print array contents
pyspark,有偿询问数据清洗和上传到数据库的问题
Google Earth engine (GEE) - long time series monthly VCI data extraction, analysis and area calculation (Mexico as an example)
Gx3001q UI instructions for upgrading 8-bit color to 16 bit color
[advanced Android] entrusted by kotlin
How to share small programs released by wechat