Results 1 to 3 of 3

Thread: Help to set up sorting algorithm

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    May 2012
    Posts
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Help to set up sorting algorithm

    Solved Creating a custom Class based upon QList.
    It works very well, it use a QList<QPair<QString, QTime>> as member and like a QMap have unique keys as QStrings.
    I'm posting the header of that class, so if anyone has troubles like mine, can implement a custom class like this, for exemple based on different QPair.

    PairTimeList.h
    Qt Code:
    1. #ifndef PAIRTIMELIST_H
    2. #define PAIRTIMELIST_H
    3. #include <QList>
    4. #include <QString>
    5. #include <QStringList>
    6. #include <QTime>
    7. #include <QPair>
    8.  
    9. class PairTimeList
    10. {
    11. public:
    12. PairTimeList();
    13. PairTimeList( QList< QPair<QString, QTime> > list);
    14.  
    15. bool contains(const QString key) const;
    16. bool contains(const QPair<QString, QTime> pair) const;
    17. bool insert(const QString str, const QTime t);
    18. bool insert(const QPair<QString, QTime> pair);
    19. bool erase(const QString key);
    20. bool erase(const QPair<QString, QTime> pair);
    21. bool erase(int position);
    22. void clear();
    23. void removeFirst();
    24. void removeLast();
    25. bool replace(int position, const QPair<QString, QTime> newpair);
    26. bool replace(const QString key, const QTime newTime);
    27. int position(const QString key) const; //return -1 if key doesn't exists
    28. QPair<QString, QTime> data(int position) const;
    29. const QPair<QString, QTime> at(int position) const;
    30. QTime time(const QString key) const;
    31. QList<QTime> times() const;
    32. QStringList keys();
    33. QStringList keys(const QTime value); //return all keys(QString) with QTime=value
    34. QStringList keysBetween(const QTime fromTime, const QTime toTime);
    35. const QList< QPair<QString, QTime> > sort_byTime() ; //BubbleSort
    36. const QList< QPair<QString, QTime> > sort_byStrings(); //BubbleSort
    37. const QList< QPair<QString, QTime> > getList() const ;
    38. QString print();
    39. int size() const;
    40. void setTime(int position, QTime t);
    41. void setTime(int position, int h, int min, int sec=0, int msec=0);
    42. void setTime(const QString key, QTime t);
    43. void setTime(const QString key, int h, int min, int sec=0, int msec=0);
    44. void addSec(int position, int sectoAdd);
    45. void addSec(const QString key, int sectoAdd);
    46. void addMsec(int position, int msecToAdd);
    47. void addMsec(const QString key, int msecToAdd);
    48. QTime deltaTime(int from1, int to2);
    49. int msecBetween(int position1, int position2);
    50. int msecBetween(const QString key1, QString key2);
    51. int secBetween(int position1, int position2);
    52. int secBetween(const QString key1, QString key2);
    53. private:
    54. QList< QPair<QString, QTime> > mylist;
    55. };
    56.  
    57. #endif // PAIRTIMELIST_H
    To copy to clipboard, switch view to plain text mode 
    Last edited by Quasar; 25th May 2012 at 14:16. Reason: spelling corrections

Similar Threads

  1. No Response when Algorithm runs...
    By revellix in forum Qt Programming
    Replies: 2
    Last Post: 13th August 2011, 17:24
  2. qt algorithm speed up problem
    By leonardhead in forum Newbie
    Replies: 3
    Last Post: 27th August 2010, 01:03
  3. qtthread to speed up the algorithm
    By leonardhead in forum Qt Programming
    Replies: 1
    Last Post: 20th August 2010, 05:09
  4. Sutherland-Hodgman algorithm of clipping
    By YaK in forum General Programming
    Replies: 0
    Last Post: 29th March 2009, 10:54
  5. Dijkstra's Algorithm
    By therealjag in forum Qt Programming
    Replies: 2
    Last Post: 6th March 2006, 10:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.