PageRenderTime 21ms CodeModel.GetById 16ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/tutorial/sorting/example2.e

http://github.com/tybor/Liberty
Specman e | 44 lines | 35 code | 4 blank | 5 comment | 0 complexity | a4113c6b6c22ed4e9474bd2eca59b3da MD5 | raw file
 1class EXAMPLE2
 2   --
 3   -- Yes it is easy to sort any COLLECTION :
 4   --
 5   --            compile -o example2 -boost example2
 6   --
 7
 8create {ANY}
 9   make
10
11feature {ANY}
12   make
13      local
14         c: COLLECTION[STRING]; sorter: COLLECTION_SORTER[STRING]; reverse_sorter: REVERSE_COLLECTION_SORTER[STRING]
15      do
16         c := {TWO_WAY_LINKED_LIST[STRING] << "dd", "bb", "aa", "cc" >> }
17         io.put_string("My collection not sorted : ")
18         print_collection(c)
19         io.put_string("My sorted collection     : ")
20         sorter.sort(c)
21         print_collection(c)
22         io.put_string("Reverse sorting          : ")
23         reverse_sorter.sort(c)
24         print_collection(c)
25      end
26
27feature {}
28   print_collection (c: COLLECTION[STRING])
29      local
30         i: INTEGER
31      do
32         from
33            i := c.lower
34         until
35            i > c.upper
36         loop
37            io.put_string(c.item(i))
38            io.put_character(' ')
39            i := i + 1
40         end
41         io.put_character('%N')
42      end
43
44end -- class EXAMPLE2