Plz help with this
How to write logic for counting sort
hello
the frequency array’s upper bound has to be the maximum element of the original array
consider an array of size 4 with elements 11 12 13 14
when accessing any of these elements freq array will go out of bound according to your code
also in the second loop where u are putting the elements back k will go out of bound for the original array as well
also here freq array takes garbage values, initialise it to zero
the correct approach is
find the max of array use this to define freq[max] and then store frequencies and then run the loop for 0 to max wherever freq > 0 keep on putting the elements in the original array