Please check the code.
Its working fine for one test case
#include
using namespace std;
void LinearTimeSort(int a[], long long int n){
int s=0;
int m=0;
long long int e=n-1;
while(m<=e){
if (a[m]==0){
swap(a[m],a[s]);
m++;
s++;
}
else if(a[m]==1){
m++;
}
else{
swap(a[m],a[e]);
e–;
}
}
}
int main(){
long long int n;
cin>>n;
int a[1000];
for(int i=0;i<n;i++){
cin>>a[i];
}
LinearTimeSort(a,n);
for(int i=0;i<n;i++){
cout<<a[i]<<endl;;
}
return 0;
}