Advertisement
Guest User

Untitled

a guest
May 28th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void show(int arr[], int count) {
  4. for (int n = 0; n < count - 1; n++)
  5. printf("%d ", arr[n]);
  6. printf("\n");
  7. }
  8.  
  9. void bubble_sort(int arr[], int count) {
  10. int x, y, z;
  11. // loop through every item
  12. for (x = 0; x < count - 1; x++) {
  13. // loop through all the items up until the current "inner" item
  14. for (y = 0; y < count - x - 1; y++) {
  15. // current value is greater than the next one? swap them
  16. if (arr[y] > arr[y + 1]) {
  17. z = arr[y];
  18. arr[y] = arr[y + 1];
  19. arr[y + 1] = z;
  20. }
  21. }
  22. }
  23. }
  24.  
  25. int main(int argc, char *argv[]) {
  26.  
  27. int arr1[] = { 1, 2, 5, 6, 7, 4, 3 };
  28. int arr2[] = { 7, 2, 3, 6, 1, 4, 5 };
  29.  
  30. bubble_sort(arr1, 7);
  31. show(arr1, 7);
  32.  
  33. bubble_sort(arr2, 7);
  34. show(arr2, 7);
  35.  
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement