1
0
mirror of https://github.com/Didnelpsun/CS408.git synced 2026-06-17 07:27:12 +08:00

更新排序

This commit is contained in:
Didnelpsun
2021-10-01 23:42:03 +08:00
parent ae1d32460e
commit 4d3dad32d5
3 changed files with 47 additions and 15 deletions

View File

@@ -63,4 +63,22 @@ bool ShellSort(LinearTable table) {
}
}
return true;
}
// 冒泡排序
bool BubbleSort(LinearTable table){
elem_type temp;
// 外循环为排序趟数一共需要length-1趟
for(int i=0;i<table.length-1;i++){
// 内循环为排序趟数i趟比较次数为length-i
// 排序完成的序列在后面
for(int j=0;j<table.length-1-i;j++){
if(table.data[j]>table.data[j+1]){
temp = table.data[j];
table.data[j] = table.data[j+1];
table.data[j+1] = temp;
}
}
}
return true;
}