Results 1 to 3 of 3

Thread: Help to set up sorting algorithm

Threaded View

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

    Default Help to set up sorting algorithm

    Hi all. I'm working on car simulator. The core is the class car who implements the physics of veicles. This class have a public function that return Qtime, the minimum time to go through a part of a track.
    One of the outputs of my application would be a table in a sqlite db like this:
    Lap | iDCar | LapTime | TotalTime | Position
    For this i have implemented a code like this (i'm not posing the original code couse a lot of function's names are not in english)
    Qt Code:
    1. QString query = " Insert into tablename ";
    2. QVector<Part> track;
    3. QVector<Car> cars;
    4. //fill vectots
    5. QMap<QString, QTime> total_time;
    6. QTime lapTime, partTime;
    7. for(int lap=1; lap<=nLap; lap++)
    8. {
    9. for(int id=0; id<cars.size(); id++)
    10. {
    11. lapTime = QTime(0,0,0,0);
    12. for(int part=0; part<track.size(); part++)
    13. {
    14. partTime = cars[id].getTime(track.at(part));
    15. lapTime = lapTime.addMsec(partTime.msecTo(QTime(0,0))); //really, qAbs() of partTime.msecTo()
    16. total_time[cars.at(id).pilotId()] = total_time[cars.at(id).pilotId()].addMsec(lapTime.msecTo(QTime(0,0)));
    17. s.append( // built a "select - union all" query.
    18. }
    19. }
    20. }
    21. qsqlQuery q;
    22. q.exec(query);
    To copy to clipboard, switch view to plain text mode 

    Now the problem is that i can't figure out how to get the position of the car at that determinated lap. I know that i have to do something with the QMap total_time that have unique car id as keys, and total time as values, but i don't know how to sort QMap values witout losing the corrispondence with keys.
    I hope someone could help me, and i apologize for my English.
    Last edited by Quasar; 24th May 2012 at 18:17. Reason: reformatted to look better

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.