> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/sidef-lang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/sidef-lang/programming_tasks/s/sorting-algorithms/gnome_sort.md).

# Gnome sort

```ruby
class Array {
    method gnomesort {
        var (i=1, j=2)
        var len = self.len
        while (i < len) {
            if (self[i-1] <= self[i]) {
                (i, j) = (j, j+1)
            }
            else {
                self[i-1, i] = self[i, i-1]
                if (--i == 0) {
                    (i, j) = (j, j+1)
                }
            }
        }
        return self
    }
}
 
var ary = [7,6,5,9,8,4,3,1,2,0]
say ary.gnomesort
```

#### Output:

```
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
```
