当前位置:网站首页>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 ;
}
}
}
}
边栏推荐
- Using jhipster to build microservice architecture
- [Zeng shuge's laser slam notes] gmapping filter based slam
- Analysis of China's integrated circuit industry chain in 2021: huge downstream market demand [figure]
- 聊聊内存模型和内存序
- How to realize data transaction
- 冒泡排序法
- Form submit onclick and onsubmit
- Swiftui component encyclopedia creating animated 3D card scrolling effects using Scrollview and geometryreader
- Tencent released the global DDoS threat report in 2021: DDoS threat has become the preferred extortion method for criminal gangs
- Initialize MySQL Gorm through yaml file
猜你喜欢

软件项目管理 8.4.软件项目质量计划
![[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

centos7 安装 MySQL 及配置 innodb_ruby

JS Part 4

mysql 数据恢复 (.ibdata1, bin log)

mysql常用指令

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

直接插入排序
![Analysis on development history, industrial chain, output and enterprise layout of medical polypropylene in China in 2020 [figure]](/img/28/ebfc25ec288627706e15a07e6bdb77.jpg)
Analysis on development history, industrial chain, output and enterprise layout of medical polypropylene in China in 2020 [figure]

Google Earth Engine(GEE)——长时间序列逐月VCI数据提取分析和面积计算(墨西哥为例)
随机推荐
TDesign update weekly report (the second week of January 2022)
[quick view] Analysis on the development status and future development trend of the global and Chinese diamond cultivation industry in 2021 [figure]
An implementation of warning bombing
JS remove first character of string
【机器学习】 吴恩达机器学习作业 ex2逻辑回归 Matlab实现
Form submit onclick and onsubmit
嵌入式软件测试工具TPT18更新全解析
【owt】owt-client-native-p2p-e2e-test vs2017构建2 :测试单元构建及运行
Three ways to export excel from pages
Analysis on the development of China's satellite navigation industry chain in 2021: satellite navigation is fully integrated into production and life, and the satellite navigation industry is also boo
Nezha panel modifies logo, small icon and other information
[Zeng shuge's laser slam notes] gmapping filter based slam
聊聊内存模型和内存序
直接插入排序
Insérer le tri directement
1058 multiple choice questions (20 points)
C. Differential Sorting
TRTC zero foundation -- Video subscription on the code
What is the reason why anonymous live OBS streaming is successful but flv video cannot be played?
Know res.send() and res.end() of Express