Guest User

Untitled

a guest
Jun 21st, 2018
75
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.  
  3. void bsort(int*);
  4. void swap(int*, int*);
  5.  
  6. int main()
  7. {
  8.     int a[5] = {5,4,3,2,1};
  9.     bsort(a);
  10.     return 0;
  11. }
  12.  
  13. void bsort(int *a)
  14. {
  15.     int x;
  16.     char i;
  17.     for (x=5; x>=0; x--)
  18.     {
  19.         for (i=0; i<x; i++)
  20.         {
  21.             if (*(a+i) > *(a+i+1))
  22.             {
  23.                 swap((a+i), (a+i+1));
  24.             }
  25.         }
  26.     }
  27.     for (x=0; x<5; x++)
  28.         printf("%d\n", a[x]);
  29. }
  30.  
  31. void swap(int*ptr1, int*ptr2)
  32. {
  33.     int tmp = *ptr1;
  34.     *ptr1 = *ptr2;
  35.     *ptr2 = tmp;
  36. }
Add Comment
Please, Sign In to add comment