Soln_for_WaveArray


#1

//It works fine.
vector Solution::wave(vector &A) {

int n=A.size();
int i=0;
sort(A.begin(),A.end());
while(i<n){
    if(i>0 && A[i-1]>A[i]){
        swap(A[i],A[i-1]);
    }
    if(i<n-1 && A[i]<A[i+1]){
        swap(A[i],A[i+1]);
    }
    if(n%2==0){
        A[n-1]=A[n-1];
    }
    i=i+2;
}
return A;

}