Skip to content

Instantly share code, notes, and snippets.

@eagsalazar
Created August 3, 2010 18:59
Show Gist options
  • Save eagsalazar/506923 to your computer and use it in GitHub Desktop.
Save eagsalazar/506923 to your computer and use it in GitHub Desktop.
#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