```
void nextPermutation(vector<int>& nums){
int i(nums.size());
int j(i);
while(--i>0 && nums[i] <= nums[i-1]);
if (i) {//if i equals 0,show that there isn't a next permutation
while(--j>i-1 && nums[j] <= nums[i-1]);//find the element bigger than nums[i-1]
swap(nums[j],nums[i-1]);
}
for (int m = i,n = nums.size()-1;m<n;m++,n-- )//exchange from i to nums.size()-1
swap(nums[m],nums[n]);
}
```