1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
#include <iostream>
#include <iterator>
#include <algorithm>
void bubblesort(int v[], int w[], int n) {
for (int i = n - 1; i > 0; i--) {
for (int j = 0; j < i; j++) {
if (v[j] > v[j + 1]) {
int vswp = v[j];
int wswp = w[j];
v[j] = v[j + 1];
v[j + 1] = vswp;
w[j] = w[j + 1];
w[j + 1] = wswp;
}
}
}
}
int main()
{
using namespace std;
int a[] = { 5, 2, 3, 1, 5, 3, 4 };
int b[] = { 1, 2, 3, 4, 5, 6, 7 };
bubblesort(a, b, 7);
copy(a, a+7, ostream_iterator<int>(cout, " "));
cout << endl;
copy(b, b+7, ostream_iterator<int>(cout, " "));
cout << endl;
}
|
1 2 3 3 4 5 5
4 2 3 6 7 1 5 | |