Advertisement
yoyolove

bubble sort

Jun 13th, 2011
157
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. contact: traitimbanggia.199x@gmail.com
  3. */
  4. #include <stdio.h>
  5.  
  6. void swap(int *a,int *b)
  7. {
  8.     int temp=*a;
  9.     *a=*b;
  10.     *b=temp;
  11. }
  12.  
  13.  
  14. void bubblesort(int Array[],int n)
  15. {
  16.     int i,count;
  17.     for(count=0;count<n-1;count++)
  18.         for(i=0;i<n-1-count;i++)
  19.             if(Array[i] > Array[i+1])
  20.                 swap(&Array[i],&Array[i+1]);
  21. }
  22.  
  23. void print(int Array[],int n)
  24. {
  25.     int i;
  26.     for(i=0;i<n;i++){
  27.         printf(" %2d",Array[i]);
  28.     }
  29. }
  30.  
  31. int main()
  32. {
  33.     int Array[] = {1,5,3,10,1};
  34.     int n =  sizeof(Array)/sizeof(Array[0]);
  35.     bubblesort(Array,n);
  36.     print(Array,n);
  37.    
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement