Why this is not giving correct input

#include
using namespace std;
void dnfsorting(int a[],int n){
int lo=0;
int mid=0;
int high=n-1;
while(mid<=high){
if(a[mid]==0){
swap(a[mid],a[lo]);
lo++;
mid++;
}
if(a[mid]==1){
mid++;
}
if(a[mid]==2){
swap(a[mid],a[high]);
high–;
}

}
return;

}
int main(){
int a[]={1,2,0,0,2,1,0,1,2};
int n=sizeof(a)/sizeof(int);
dnfsorting(a,n);
for(int i=0;i<n;i++){
cout<<a[i]<<" ";
}
return 0;
}

Hey @lovepreet_singh share your code using ide.codingblocks.com so that i can help you with same.

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.