Sorting in o(n) time

please tell what i need to change .everything look fine to me.

#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)
{
  while(a[i]!=0)
    {
		cout<<i<<endl;
		a[i]--;     
     }
	 i++;
}

return 0;

}