Advertisement
rafikamal

Bubble Sort

Feb 10th, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.44 KB | None | 0 0
  1. #include <stdio.h>
  2. #define SIZE 7
  3.  
  4. void bubbleSort(int *A, int length)
  5. {
  6.     int i, j;
  7.    
  8.     for(i = 1; i <= length - 1; i++)
  9.     {
  10.         for(j = 0; j < length - i; j++)
  11.             if(A[j] > A[j + 1])
  12.             {
  13.                 int temp = A[j];
  14.                 A[j] = A[j + 1];
  15.                 A[j + 1] = temp;
  16.             }
  17.     }
  18. }
  19.  
  20. int main()
  21. {
  22.     int arr[SIZE] = {11, 1, 8, 5, 6, 8, 4};
  23.     int i;
  24.    
  25.     bubbleSort(arr, SIZE);
  26.    
  27.     for(i = 0; i < SIZE; i++)
  28.         printf("%d ", arr[i]);
  29.    
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement