Descending countingSort in Julia

Hi everyone, I recently started programming in Julia programming language. I got a task from my profesor to create a countingSort algorythm and I did it. My question is what adjustments should I make so array would be in descending order (besides using (reverse(countingSort)). Also, is there something to add in my algorythm, program is working good, but there still might be some errors. Anyways thank you for help in advance!


First of all, don’t post screenshots of code. If anybody would want to run it in order to help you, he’d have to type it all out again instead of just copy-pasting.
Instead of a picture, you can use the backtick character ` to delimit code blocks like so.
And you can write three consecutive ` followed by a language tag (most likely julia) to enable multi-line code blocks with Syntax highlighting.



using LinearAlgebra
function countingSort(a)

Concerning the code:
I’m assuming it’s expected to work properly only for vectors of integers. Still, you should make your counter of type Int, since, well, counts are integers by nature. To find out how to do this, you may want to type ?zeros into the REPL :slight_smile:

Your code also fails if a contains 0s or negative numbers. Do you want to fix this?

Edit: reversing should be as simple as replacing for i in n:m with for i in m:-1:n