Counting sort algorithm


why there is segmentation fault in this?

Hello @lovely i am checking your code.

Hello @lovely there is no need of thinking of inpplace technique as well .
you can think like that you have to just do counting sort .
from where you have seen the video for this concept?

apna college aman dhattarwal channel. but the instructor performed the same code and it ws running

@lovely dont go with this approach just count the occurence of elements in the frequency type array for the elements and then you can input from starting if the freq is not zero at that index.

but why i cannot do this one

@lovely no you can do any of your choice but it is complicated.
do you still want me to corect this code.
or tell yout the approach which i am telling?

correct this one as i want to first find my mistake .and then you can also tell your approach also

This is the approach which i am talking about.
https://ide.codingblocks.com/s/388801 and please wait i am correcting your code as well.

1 Like

thanks for sharing your approach its comparitvely easier than my approach. :+1:

@lovely your corrected code:


Happy Learning!!

1 Like

why u have used #define n 256 .i mean what is use of it?

Hey @lovely see in the function i have made your loop run for 256 times by defining N
this is because we have total of 256 characters.

but why we are running these loop 256 times?what is use of it.

@lovely because there coudl any character and all the characters comes in the range of 256.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.