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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| #include "assert.h" #include <iostream> using namespace std;
void Sort(int *arr, int m) { int i = 0, j = 0, k = m - 1, temp; while (j <= k) { if (arr[j] == 1) { temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; if (i < j) { cout << i << "<--->" << j << endl; } i++; j++; } else if (arr[j] == 2) { j++; } else { temp = arr[j]; arr[j] = arr[k]; arr[k] = temp; if (j < k) { cout << j << "<--->" << k << endl; } k--; } } for (int i = 0; i < m; i++) { cout << arr[i]; } cout << endl; }
int main() { int n; cin >> n; int * a= new int[n]; for (int i=0;i<n;i++) cin>>a[i]; Sort(a,n); }
|