diff options
Autocommit at 08.05.2022 @ 08:27
1 files changed, 8 insertions, 6 deletions
| -rw-r--r-- | src/Services/EventService.cpp | 14 |
diff --git a/src/Services/EventService.cpp b/src/Services/EventService.cpp index eb57f41..5b79faa 100644 --- a/src/Services/EventService.cpp +++ b/src/Services/EventService.cpp @@ -161,20 +161,22 @@ String EventService::createSeatingString(const char* name, const Date& date, uns unsigned indexToInsertWhenTicketSort(const List<Event>& elem, unsigned topN, unsigned ticketCount) { for (unsigned i = 0; i < elem.get_count() && i < topN; i++) { - if (elem[i].get_tickets().get_count() < ticketCount) + if (elem[i].get_tickets().get_count() <= ticketCount) return i; } return topN; } -StatusCode EventService::queryMostWatched(unsigned topN) { +List<Event> EventService::queryMostWatched(unsigned topN) { List<Event> result; for (unsigned i = 0; i < events.get_count(); i++) { - if (result.get_count() > 10 && result[10].get_tickets().get_count() > events[i].get_tickets().get_count()) - continue; - - + unsigned ind = indexToInsertWhenTicketSort(result, topN, events[i].get_tickets().get_count()); + if (ind < topN) + result.insertAt(events[i], ind); + if (result.get_count() == topN) + result.removeAt(topN); } + return result; } template <typename T> |
