Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Solution::arrange(vector<int> &A) {
- int sz = A.size(), j, tempKey, tempValue;
- for (int i = 0; i < sz; i++) {
- tempKey = i;
- tempValue = A[i];
- while (A[i] < sz) {
- for (j = 0; A[j] != tempKey; j++);
- A[j] = tempValue + sz;
- tempValue = tempKey;
- tempKey = j;
- }
- }
- for (int i = 0; i < sz; i++) {
- A[i] -= sz;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement