ds
This commit is contained in:
parent
45c22c078d
commit
d65bda55da
@ -43,14 +43,13 @@ int main(){
|
|||||||
databaza[size].votes=value;
|
databaza[size].votes=value;
|
||||||
// Zvacsite pocet zaznamov
|
// Zvacsite pocet zaznamov
|
||||||
size+=1;
|
size+=1;
|
||||||
}
|
|
||||||
else {
|
|
||||||
// pripocitajte pocet hlasov
|
|
||||||
databaza[id].votes+=value;
|
|
||||||
}
|
|
||||||
if(size>1)
|
if(size>1)
|
||||||
qsort(databaza, size, sizeof(struct student), compare);
|
qsort(databaza, size, sizeof(struct student), compare);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
databaza[id].votes+=value;
|
||||||
|
}
|
||||||
|
}
|
||||||
printf("Vysledky:\n");
|
printf("Vysledky:\n");
|
||||||
for(int idx=0;databaza[idx].name[0]!='\0';idx++)
|
for(int idx=0;databaza[idx].name[0]!='\0';idx++)
|
||||||
printf("%d %s", databaza[idx].votes, databaza[idx].name);
|
printf("%d %s", databaza[idx].votes, databaza[idx].name);
|
||||||
@ -59,8 +58,6 @@ int main(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
int find_student(struct student* students,int size, const char* name){
|
int find_student(struct student* students,int size, const char* name){
|
||||||
// Dopíšte cyklus, ktorý prejde všetky položky v databáze
|
|
||||||
// a ak nájde zhodné meno tak vráti jeho index.
|
|
||||||
for(int idx=0; idx<size;idx++)if(strcmp(students[idx].name,name)==0)return idx;
|
for(int idx=0; idx<size;idx++)if(strcmp(students[idx].name,name)==0)return idx;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -68,8 +65,6 @@ int find_student(struct student* students,int size, const char* name){
|
|||||||
int compare(const void* p1, const void* p2){
|
int compare(const void* p1, const void* p2){
|
||||||
struct student* s1 = (struct student*)p1;
|
struct student* s1 = (struct student*)p1;
|
||||||
struct student* s2 = (struct student*)p2;
|
struct student* s2 = (struct student*)p2;
|
||||||
// s1->votes je počet hlasov
|
|
||||||
// s1->name je meno študenta
|
|
||||||
return (s2->votes)-(s1->votes);
|
return (s2->votes)-(s1->votes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user