Advertisement
joy007

bubble_sort

Aug 1st, 2014
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define SIZE 6
  4.  
  5. int main(void)
  6. {
  7. int bubble[] = { 95, 60, 6, 87, 50, 24 };
  8. int inner, outer, temp, x;
  9.  
  10. /*Display original array */
  11. puts("Original Array: ");
  12. for(x = 0; x < SIZE; x++)
  13. printf("%d\t", bubble[x]);
  14. printf("\n\n");
  15.  
  16. /*Bubble sort */
  17. for(outer = 0; outer < SIZE - 1; outer++)
  18. {
  19. for(inner = outer + 1; inner < SIZE; inner++)
  20. {
  21. if(bubble[outer] > bubble[inner])
  22. {
  23. temp = bubble[outer];
  24. bubble[outer] = bubble[inner];
  25. bubble[inner] = temp;
  26. }
  27. }
  28. }
  29.  
  30. /*Display sorted array */
  31. puts("Sorted Array:");
  32. for(x = 0; x <SIZE; x++)
  33. printf("%d\t", bubble[x]);
  34. putchar('\n');
  35.  
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement