close
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
int main()
{
    int n=0;
    while(scanf("%d",&n)!=EOF){
        int input[n];
        for(int i=0;i<n;i++)
        {
            input[i]=0;
            scanf("%d",&input[i]);
        }
        int count=0;
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n-1;j++)
            {
                if(input[j]>input[j+1])
                {
                    std::swap(input[j],input[j+1]);
                    count+=1;
                }
            }
        }
        printf("Minimum exchange operations : %d\n",count);
    }
    return 0;
}
#buble_sort #swap
arrow
arrow
    文章標籤
    sort swap
    全站熱搜

    Nate_Tang 發表在 痞客邦 留言(0) 人氣()