Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void show(int arr[], int count) {
- for (int n = 0; n < count - 1; n++)
- printf("%d ", arr[n]);
- printf("\n");
- }
- void bubble_sort(int arr[], int count) {
- int x, y, z;
- // loop through every item
- for (x = 0; x < count - 1; x++) {
- // loop through all the items up until the current "inner" item
- for (y = 0; y < count - x - 1; y++) {
- // current value is greater than the next one? swap them
- if (arr[y] > arr[y + 1]) {
- z = arr[y];
- arr[y] = arr[y + 1];
- arr[y + 1] = z;
- }
- }
- }
- }
- int main(int argc, char *argv[]) {
- int arr1[] = { 1, 2, 5, 6, 7, 4, 3 };
- int arr2[] = { 7, 2, 3, 6, 1, 4, 5 };
- bubble_sort(arr1, 7);
- show(arr1, 7);
- bubble_sort(arr2, 7);
- show(arr2, 7);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement