voidnextPermutation(vector<int>& nums){ int size = nums.size(); if (size <= 1)return; int* tmp = newint[size]; int i; tmp[size - 1] = nums.back(); for (i = size - 1; i > 0; i--) { int j = nums[i]; int k = nums[i - 1]; tmp[i-1] = k; if (j > k) { sort(tmp + i - 1, tmp + size); for (int x = size; x >= i; x--) nums.pop_back(); int x; for (x = size - 2; x >=0; x--) { if (tmp[x] == k) { k = tmp[x + 1]; nums.push_back(k); break; } } int y = x + 1; for (x = i - 1; x < size; x++) if (x!=y) nums.push_back(tmp[x]); break; } } if (i == 0) { nums.clear(); for (i = size-1; i >=0; i--) nums.push_back(tmp[i]); } }