/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

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