题目描述
在一个数组中, 左边的数如果比右边的数大, 则折两个数构成一个逆序对, 请打印所有逆序对和个数
解法1:暴力法
解法2:归并法
测试结果及代码
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <algorithm>
using namespace std;
const int num = 3;
void printArray(int a[], int N) {
for (int i = 0; i < N; ++i) {
cout << a[i] << " ";
}
cout << endl;
}
void Swap(int &x, int &y) {
int t = x;
x = y;
y = t;
}
void compare(int a[], int N, int &sum) {
for (int i = 0; i < N - 1; ++i) {
for (int j = i + 1; j < N; ++j) {
if (a[i] > a[j])