# Descending countingSort in Julia

**URL:** https://discourse.julialang.org/t/descending-countingsort-in-julia/53151
**Category:** New to Julia
**Created:** [January 11, 2021, 9:48am UTC](https://discourse.julialang.org/t/descending-countingsort-in-julia/53151 "2021-01-11T09:48:40Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Djape](https://avatars.discourse-cdn.com/v4/letter/d/e9bcb4/32.png) [@Djape](https://discourse.julialang.org/u/Djape)
#### Post date: [January 11, 2021, 9:48am UTC](https://discourse.julialang.org/t/descending-countingsort-in-julia/53151/1 "2021-01-11T09:48:40Z")

</div>

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!

 ![image](https://global.discourse-cdn.com/julialang/original/3X/b/b/bb312c46cc6993a665496005aa8cfda1df569db7.png)

---

<div class="post-metadata">

### Author: ![FPGro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fpgro/32/20822_2.png) [@FPGro](https://discourse.julialang.org/u/FPGro)
#### Post date: [January 11, 2021, 10:50am UTC](https://discourse.julialang.org/t/descending-countingsort-in-julia/53151/2 "2021-01-11T10:50:57Z")

</div>

Hi,

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.

So  
```julia  
code…  
```

Becomes:

```julia
using LinearAlgebra
function countingSort(a)
... 
end

```

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 🙂

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`
