Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int arr[11] = {2, 5, 11, -8, 444, 66, 9, 18, 111, 1};
- int size = 10; // Размер массива или кол-во элементов
- int counter = 0;
- void swap(int &a, int &b);
- void PrintArray ();
- void sort(int *a, int n);
- ////////////////////////////////////////////////////
- int main() //
- {
- PrintArray();
- sort(arr, size);
- printf("counter = %d \n", counter);
- }
- /////////////////////////////////////////////////////
- void sort(int *a, int n) //
- {
- int F = 0;
- L_01:
- for(int x = 0; x < n-1; x++)
- {
- if(a[x] > a[x+1])
- {
- swap(a[x], a[x+1]);
- PrintArray();
- F = 1;
- }
- }
- printf("\n");
- if(F == 1) { F = 0; goto L_01; }
- }
- /////////////////////////////////////////////////////
- void swap(int &a, int &b) //
- {
- int buf = a;
- a = b;
- b = buf;
- counter ++;
- }
- //////////////////////////////////////////////////////
- void PrintArray() //
- {
- for(int x = 0; x < size; x++)
- {
- printf("%d, ", arr[x]);
- }
- printf("\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement