mirror of
https://github.com/krahets/hello-algo.git
synced 2025-01-23 14:20:29 +08:00
Fix bubble_sort.c
This commit is contained in:
parent
d0f4fa69a6
commit
d9686e57dd
@ -11,7 +11,7 @@ void bubbleSort(int nums[], int size) {
|
||||
// 外循环:未排序区间为 [0, i]
|
||||
for (int i = size - 1; i > 0; i--) {
|
||||
// 内循环:将未排序区间 [0, i] 中的最大元素交换至该区间的最右端
|
||||
for (int j = 0; j < size - 1 - i; j++) {
|
||||
for (int j = 0; j < i; j++) {
|
||||
if (nums[j] > nums[j + 1]) {
|
||||
int temp = nums[j];
|
||||
nums[j] = nums[j + 1];
|
||||
@ -27,7 +27,7 @@ void bubbleSortWithFlag(int nums[], int size) {
|
||||
for (int i = size - 1; i > 0; i--) {
|
||||
bool flag = false;
|
||||
// 内循环:将未排序区间 [0, i] 中的最大元素交换至该区间的最右端
|
||||
for (int j = 0; j < size - 1 - i; j++) {
|
||||
for (int j = 0; j < i; j++) {
|
||||
if (nums[j] > nums[j + 1]) {
|
||||
int temp = nums[j];
|
||||
nums[j] = nums[j + 1];
|
||||
|
Loading…
Reference in New Issue
Block a user