From edb0ecca9272e136747118c991fd3b409c7df9af Mon Sep 17 00:00:00 2001 From: st529yr Date: Fri, 22 Mar 2024 00:13:59 +0100 Subject: [PATCH] funguje --- cv5/program.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cv5/program.c b/cv5/program.c index 47db4c1..088454d 100644 --- a/cv5/program.c +++ b/cv5/program.c @@ -18,6 +18,17 @@ int find_student_index(Student* students, int num_students, const char* meno) { return -1; // Študent neexistuje } +int compare(const void* p1, const void* p2) { + const Student* s1 = (const Student*)p1; + const Student* s2 = (const Student*)p2; + // Porovnanie podľa počtu hlasov + if (s1->hlasov != s2->hlasov) { + return s2->hlasov - s1->hlasov; // Zoradenie zostupne + } + // Ak majú rovnaký počet hlasov, zoradíme podľa mena + return strcmp(s1->meno, s2->meno); +} + int main() { char line[SIZE]; int num_students = 0; @@ -74,6 +85,9 @@ int main() { } } + // Triedenie databázy + qsort(students, num_students, sizeof(Student), compare); + // Výpis výsledkov printf("Vysledky:\n"); for (int i = 0; i < num_students; i++) {