yoyolove

bubble sort

Jun 13th, 2011
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. /* Coding by YoYoLove - girlxitin.com
  2. */
  3. #include <stdio.h>
  4.  
  5. void swap(int *a,int *b)
  6. {
  7.     int temp=*a;
  8.     *a=*b;
  9.     *b=temp;
  10. }
  11.  
  12.  
  13. void bubblesort(int Array[],int n)
  14. {
  15.     int i,count;
  16.     for(count=0;count<n-1;count++)
  17.         for(i=0;i<n-1-count;i++)
  18.             if(Array[i] > Array[i+1])
  19.                 swap(&Array[i],&Array[i+1]);
  20. }
  21.  
  22. void print(int Array[],int n)
  23. {
  24.     int i;
  25.     for(i=0;i<n;i++){
  26.         printf(" %2d",Array[i]);
  27.     }
  28. }
  29.  
  30. int main()
  31. {
  32.     int Array[] = {1,5,3,10,1};
  33.     int n =  sizeof(Array)/sizeof(Array[0]);
  34.     bubblesort(Array,n);
  35.     print(Array,n);
  36.    
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment