tcs1f

 #include <stdio.h>


void bubble_sort(int arr[], int n, int *swaps) {

    *swaps = 0;

    for (int i = 0; i < n; i++)

        for (int j = 0; j < n - i - 1 && ((*swaps)++, arr[j] > arr[j + 1]); j++) {

            int temp = arr[j];

            arr[j] = arr[j + 1];

            arr[j + 1] = temp;

        }

}


int main() {

    int n, swaps = 0;

    scanf("%d", &n);

    

    int arr[n];

    for (int i = 0; i < n; i++) scanf("%d", &arr[i]);


    bubble_sort(arr, n, &swaps);


    printf("%d\n", swaps);


    return 0;

}


Comments

Popular posts from this blog

LATEST TECHNOLOGIES

tcs1dsu

tcs1c