-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
263 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,41 @@ | ||
#include <stdio.h> | ||
|
||
void BubbleSort(int arr[], int len) { | ||
void bubble_sort(int arr[], int n) { | ||
int i, j, tmp; | ||
for (i = 0; i < len - 1; i++) { | ||
for (j = 0; j < len - i - 1; j++) { | ||
if (arr[j] > arr[j + 1]) { | ||
tmp = arr[j]; | ||
arr[j] = arr[j + 1]; | ||
arr[j + 1] = tmp; | ||
for (i = 0; i < n - 1; i++) { | ||
for (j = 0; j < n - i - 1; j++) { | ||
if (arr[j] > arr[j + 1]) { | ||
tmp = arr[j]; | ||
arr[j] = arr[j + 1]; | ||
arr[j + 1] = tmp; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
void BubbleSortQuicker(int arr[], int len) { | ||
void bubble_sort_quicker(int arr[], int n) { | ||
int i, j, tmp, flag; | ||
for (i = 0; i < len - 1; i++) { | ||
for (i = 0; i < n - 1; i++) { | ||
flag = 0; | ||
for (j = 0; j < len - i - 1; j++) { | ||
if (arr[j] > arr[j + 1]) { | ||
tmp = arr[j]; | ||
arr[j] = arr[j + 1]; | ||
arr[j + 1] = tmp; | ||
flag = 1; | ||
for (j = 0; j < n - i - 1; j++) { | ||
if (arr[j] > arr[j + 1]) { | ||
tmp = arr[j]; | ||
arr[j] = arr[j + 1]; | ||
arr[j + 1] = tmp; | ||
flag = 1; | ||
} | ||
} | ||
if (!flag) return; | ||
} | ||
} | ||
} | ||
|
||
|
||
int main() { | ||
int arr[] = { 7, 2, 5, 3, 8}; | ||
int len = sizeof(arr) / sizeof(*arr); | ||
BubbleSort(arr, len); | ||
// BubbleSortQuicker(arr, len); | ||
int n = sizeof(arr) / sizeof(*arr); | ||
bubble_sort(arr, n); | ||
// bubble_sort_quicker(arr, n); | ||
printf("Sort result:\n"); | ||
for (int i = 0; i < len; i++) | ||
for (int i = 0; i < n; i++) | ||
printf("%d ", arr[i]); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.