turbo sort problem

please check the code below and please let me know why it is showing wrong answer on my submission and the code works well on my machine

link for the problem is here turbosort

#include<stdio.h>

int main()
{
int t,a[1000000]={},i,n;

scanf("%d",&t);

for(i=0;i<t;i++)
{
	scanf("%d",&n);
	a[n]++;
}

for(i=0;i<1000000;i++)
{
	if(a[i]!=0)
		printf("%d\n",i);
}


return 0;

}

Either you can implement counting sort or even if you use the inbulit sort function you will get AC

Here is the code using the inbuilt sort function-it is included in the header file ‘algorithm’

Here is the solution[here][1]

hope this helps

Happy coding
[1]: http://ideone.com/n8heaE


This is the counting sort code. Here the code is based on sorting letters. Make a small modification and your counting sort will be right :slight_smile:

your code is not giving correct output for duplicates element like
5
1
2
3
2
1

I have debugged your code. Your problem with your code was that each time you print the value we have to decrement the count in the array. here is the debugged codehere

If you have any doubt on counting sort first read what it is and then visualize it here When we visualize something that will be through!! Hope this helps :slight_smile:

Happy Coding

1 Like