**解题思路:
首先定义一个数组arr与给定数组相同并排序,定义双指针,由于排序是满足一小一大一小一大的顺序,所以可以从思想上把数组分为一大一小的两个序列,要让双指针分别从小序列和大序列最大位置出发,一直到最小,分别放入nums数组中,之所以从最大到最小,而不是从最小到最大,是因为如果序列太短,小序列的最大可能和大序列的最小相邻,而这两如果值相同就不满足了,代码如下:
**
class Solution {
public:
void wiggleSort(vector<int>& nums) {
vector<int> arr = nums;
sort(arr.begin(), arr.end());
int n = arr.size();
int index = 0;
int line = n % 2 == 0 ? n / 2 : n / 2 + 1;
for(int i = line - 1, j = n - 1; i >= 0; i --, j --) {
nums[index ++] = arr[i];
if(j >= line)
nums[index ++] = arr[j];
}
}
};