Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void bsort(int*);
- void swap(int*, int*);
- int main()
- {
- int a[5] = {5,4,3,2,1};
- bsort(a);
- return 0;
- }
- void bsort(int *a)
- {
- int x;
- char i;
- for (x=5; x>=0; x--)
- {
- for (i=0; i<x; i++)
- {
- if (*(a+i) > *(a+i+1))
- {
- swap((a+i), (a+i+1));
- }
- }
- }
- for (x=0; x<5; x++)
- printf("%d\n", a[x]);
- }
- void swap(int*ptr1, int*ptr2)
- {
- int tmp = *ptr1;
- *ptr1 = *ptr2;
- *ptr2 = tmp;
- }
Add Comment
Please, Sign In to add comment