mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-24 10:06:28 +08:00
fix(codes/c): Fix bubble_sort.c (#983)
This commit is contained in:
parent
2e130d4bbc
commit
d67c458caa
1 changed files with 2 additions and 2 deletions
|
@ -9,7 +9,7 @@
|
|||
/* 冒泡排序 */
|
||||
void bubbleSort(int nums[], int size) {
|
||||
// 外循环:未排序区间为 [0, i]
|
||||
for (int i = 0; i < size - 1; i++) {
|
||||
for (int i = size - 1; i > 0; i--) {
|
||||
// 内循环:将未排序区间 [0, i] 中的最大元素交换至该区间的最右端
|
||||
for (int j = 0; j < size - 1 - i; j++) {
|
||||
if (nums[j] > nums[j + 1]) {
|
||||
|
@ -24,7 +24,7 @@ void bubbleSort(int nums[], int size) {
|
|||
/* 冒泡排序(标志优化)*/
|
||||
void bubbleSortWithFlag(int nums[], int size) {
|
||||
// 外循环:未排序区间为 [0, i]
|
||||
for (int i = 0; i < size - 1; i++) {
|
||||
for (int i = size - 1; i > 0; i--) {
|
||||
bool flag = false;
|
||||
// 内循环:将未排序区间 [0, i] 中的最大元素交换至该区间的最右端
|
||||
for (int j = 0; j < size - 1 - i; j++) {
|
||||
|
|
Loading…
Reference in a new issue