fork download
  1. #include <stdio.h>
  2.  
  3. typedef int element;
  4.  
  5. void bubbleSort(element a[], int size) {
  6. element temp;
  7. printf("\n정렬할 원소 : ");
  8. for (int t = 0; t < size; t++) {
  9. printf("%d ", a[t]);
  10. }
  11. printf("\n\n 버블 정렬 수행 \n");
  12.  
  13. for (int i = size - 1; i > 0; i--) {
  14. printf("\n %d 제외>> ", size - i);
  15. for (int j = 0; j < i; j++) {
  16. if (a[j] > a[j + 1]) {
  17. temp = a[j];
  18. a[j] = a[j + 1];
  19. a[j + 1] = temp;
  20. }
  21. }
  22. printf("\n\t");
  23. for (int t = 0; t < size; t++) {
  24. printf("%3d ", a[t]);
  25. }
  26. }
  27. printf("\n");
  28. }
  29.  
  30. int main() {
  31. int arr[8] = {69, 10, 30, 2, 16, 8, 31, 22};
  32. bubbleSort(arr, 8);
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
정렬할 원소 : 69 10 30 2 16 8 31 22 

 버블 정렬 수행 

 1 제외>> 
	 10  30   2  16   8  31  22  69 
 2 제외>> 
	 10   2  16   8  30  22  31  69 
 3 제외>> 
	  2  10   8  16  22  30  31  69 
 4 제외>> 
	  2   8  10  16  22  30  31  69 
 5 제외>> 
	  2   8  10  16  22  30  31  69 
 6 제외>> 
	  2   8  10  16  22  30  31  69 
 7 제외>> 
	  2   8  10  16  22  30  31  69