Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 36 lines (29 sloc) 0.692 kb
1b04c09 @MikeChristianson gnome sort written in io with @shumway
authored
1 List valueOutOfPlace := method(position,
2 at(position) < at(position - 1)
3 )
4
5 List stepItBack := method(position,
6 swapIndices(position-1, position)
a749370 @MikeChristianson formatting changes for consistency and readability
authored
7 if(position > 1,
8 position = position - 1
9 )
1b04c09 @MikeChristianson gnome sort written in io with @shumway
authored
10 position
11 )
12
13 List moveForward := method(position,
14 position + 1
15 )
16
17 List gnomeSort := method(
18 position := 1
19 while(position < size,
20 if(valueOutOfPlace(position),
21 position = stepItBack(position),
a749370 @MikeChristianson formatting changes for consistency and readability
authored
22 position = moveForward(position)
23 )
1b04c09 @MikeChristianson gnome sort written in io with @shumway
authored
24 )
25 )
26
27 l := list(3,1,5,2,13,14,12,15)
28 expected := list(1,2,3,5,12,13,14,15)
29
30 l gnomeSort
31
32 if(l == expected,
33 "they're the same" println,
34 Exception raise("they're not the same expected\n #{expected} but got\n #{l}" interpolate)
35 )
Something went wrong with that request. Please try again.