Sorting 0 1 2.please .check my code

#include
using namespace std;

int main() {

int n;
cin>>n; //size of array

int a[3],i,p;

for(i=0;i<n;i++)
 { 
    cin>>p;
    a[p]++;
 }

i=0;

  while(i<3)
    {
		cout<<i<<endl;
		a[i]--; 
		    
		if(a[i]==0)
		i++;

     }	 	

return 0;

}

@Asis take two array one for frequency and one for input
update the frequency of the elements in the array in frquency array run your loop for the maximum value present in the array like
for(int i=0;i<=max;i++){
for(int j=1;j<=count[i];j++){
cout<<i<<endl;
}
}
don’t use cin>>p
input array like
cin>>a[i];
then update the frequency
count[a[i]]++;