Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef SL_H
- #define SL_H
- #include <list>
- #include <algorithm>
- #include <iterator>
- #include <functional>
- template<typename T, class Compare = std::less<T>>
- class SortedList
- {
- typedef std::list<T> l_type;
- typedef typename l_type::const_iterator l_it;
- l_type l;
- public:
- SortedList() { }
- void insert(T e) { l.insert(std::lower_bound(l.begin(), l.end(), e, Compare()), e); }
- int size() const { return l.size(); }
- T front() const { return l.front(); }
- // 3-as
- void remove(T e) { l.remove(e); }
- T back() const { return l.back(); }
- // 4-es
- l_it begin() const { return l.cbegin(); }
- l_it end() const { return l.cend(); }
- // 5-ΓΆs
- template <typename Iterator>
- SortedList(Iterator begin, Iterator end) { for (Iterator it = begin; it != end; it++) insert(*it); }
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement