Sorti in linear time problem

#include
using namespace std;
void countSort(int arr[],int n)
{
int j;
int freq[3]={0};
for( int i=0;i<n;i++)
{
j=arr[i];
freq[j]++;
}
for(int i=0;i<3;i++)
{

cout<<freq[i]<<endl;

}
int array[n];
int k=0;
for(int i=0;i<3;i++)
{

while(freq[i]>0)
{
array[k]=i;
freq[i]–;
k++;
}

}
for(int i=0;i<n;i++)
{
cout<<array[i];
}
for(int i=0;i<n;i++)
{

arr[i]=array[i];

}
}

int main()
{
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}

countSort(arr,n);

}

hi,got the correct solution

Hi @mstevathiya, pls mark your doubt as resolved.

hey mohit, please mark your doubt as resolved.

1 Like