Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int arr[10] = {2, 9, 6, 5, 10, 7, 8, 1, 4, 3};
- int size = 10;
- void swap(int &a, int &b);
- void print_arr();
- void sort();
- ////////////////////////////////////////////////////
- int main() //
- {
- print_arr();
- sort();
- }
- ///////////////////////////////////////////////////
- void sort()
- {
- for(int i = 0; i < size-1; i++)
- {
- if(arr[i] > arr[i+1])
- {
- swap(arr[i] , arr[i+1]);
- print_arr();
- }
- }
- }
- ////////////////////////////////////////////////////
- void print_arr() //
- {
- for(int i = 0; i < size; i++)
- {
- printf("%d, ", arr[i]);
- }
- printf("\n");
- }
- // Эта функция нужна для обмена содержимого переменных a & b
- /////////////////////////////////////////////////////
- void swap(int &a, int &b) //
- {
- // printf("a = %d, b = %d \n", a, b);
- int Buf = a;
- a = b;
- b = Buf;
- /// printf("a = %d, b = %d \n", a, b);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement