gnomesort.py |
|
---|---|
This is an implementation of the Gnome sort algorithm in Python |
|
Dick Grune describes Gnome sort as follows: Gnome Sort is based on the technique used by Dutch Garden Gnomes. Here is how a garden gnome sorts a line of flower pots. |
|
Boundary conditions: if there is no previous pot, he steps forwards; |
|
if there is no pot next to him, he is done. |
|
Basically, he looks at the flower pot next to him and the previous one; if they are in the right order he steps one pot forward, |
|
otherwise he swaps them and steps one pot backwards. |
|