Created
August 3, 2010 18:59
-
-
Save eagsalazar/506923 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef SORTEDLIST_H | |
#define SORTEDLIST_H | |
#include <QList> | |
#include <QObject> | |
#include <QtAlgorithms> | |
template <typename T> | |
class SortedList : public QList<T> | |
{ | |
public: | |
explicit SortedList(); | |
int insert(const T &t); | |
private: | |
QList<int>::iterator itr; | |
}; | |
template <typename T> | |
SortedList<T>::insert(const T &t) | |
{ | |
// Find where the new item is or should be inserted | |
// This requires that the template class T implement | |
// both operator<() and operator==(). | |
itr = qLowerBound(list.begin(), list.end(), t); | |
if(t != at(itr)) | |
{ | |
insert(itr, t); | |
} | |
} | |
#endif // SORTEDLIST_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment