diff options
author | Max Horn | 2006-04-04 23:55:47 +0000 |
---|---|---|
committer | Max Horn | 2006-04-04 23:55:47 +0000 |
commit | bec09d30945c7dc143dc4ccd5e2fba1dcaccaac1 (patch) | |
tree | ae23245d53ee0b48082405b7d9409854423a3610 /common | |
parent | 66d8b85463da60f0b88c3f7d6068df502d940546 (diff) | |
download | scummvm-rg350-bec09d30945c7dc143dc4ccd5e2fba1dcaccaac1.tar.gz scummvm-rg350-bec09d30945c7dc143dc4ccd5e2fba1dcaccaac1.tar.bz2 scummvm-rg350-bec09d30945c7dc143dc4ccd5e2fba1dcaccaac1.zip |
Turned FSList::sort into a generic function which can be applied to anything which implements comparable iterators (like Array, List, or plain C arrays)
svn-id: r21617
Diffstat (limited to 'common')
-rw-r--r-- | common/func.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/common/func.h b/common/func.h index 10c80e66f5..e2cd20fdb3 100644 --- a/common/func.h +++ b/common/func.h @@ -62,6 +62,28 @@ GENERATE_TRIVIAL_HASH_FUNCTOR(unsigned long); #undef GENERATE_TRIVIAL_HASH_FUNCTOR +// Simple sort function, modelled after std::sort. +// Use it like this: sort(container.begin(), container.end()). +// Also work on plain old int arrays etc. +template <typename T> +void sort(T first, T last) { + if (first == last) + return; + + // Simple selection sort + T i(first); + for (; i != last; ++i) { + T min(i); + T j(i); + ++j; + for (; j != last; ++j) + if (*j < *min) + min = j; + if (min != i) + SWAP(*min, *i); + } +} + } // End of namespace Common |