Check my code plz

#include<bits/stdc++.h>

using namespace std;
int main()
{
int a[6]={1,3,4,2,7,8};

for(int i=0;i<6;i+=2)
{
	if(a[i]<a[i+1])
	swap(a[i],a[i+1]);
}

for(int i=1;i<6;i+=2)
{
	if(a[i]>a[i+1])
	swap(a[i],a[i+1]);
}

	for(int i=0;i<6;i++)
	cout<<a[i]<<" ";
	
	return 0;

}

plz check it,is it correct?

hey Nikhil, take current element as reference and in the first loop check whether current element is greater than left element or not. In second loop check whether current element is greater than Right element or not.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.