Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Services / EventService.cpp
diff options
context:
space:
mode:
Commit3a151329504e0c9a3a80669654c7ab8bf2036ce2 (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-05-08 08:27:55 +0300
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-05-08 08:27:55 +0300
Filesb45bc5acb1a1dee629f57fa448f8b31f25332959 /src/Services/EventService.cpp
FMI-OOP-P1_TicketSystem-3a151329504e0c9a3a80669654c7ab8bf2036ce2.tar
FMI-OOP-P1_TicketSystem-3a151329504e0c9a3a80669654c7ab8bf2036ce2.tar.gz
FMI-OOP-P1_TicketSystem-3a151329504e0c9a3a80669654c7ab8bf2036ce2.zip
Parent8fdd50592e1f9fef9a4ff261e771924d7c688741 (diff)
Autocommit at 08.05.2022 @ 08:27
1 files changed, 8 insertions, 6 deletions
-rw-r--r--src/Services/EventService.cpp14
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>