我记得 unique 会把重复元素移到数组最后,但是以下代码:
#include<bits/stdc++.h>
using namespace std;
int a[20]={0,1,2,2,2,3,3,5},n=7;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
unique(a+1,a+n+1);
for(int i=1;i<=n;i++) cout<<a[i]<<" ";
cout<<"\n";
return 0;
}
的输出为 1 2 3 5 3 3 5
,这是为什么?