This commit is contained in:
Michaela Šaková 2019-03-25 15:37:46 +01:00
parent b83500591d
commit c9a74987d0
6 changed files with 15 additions and 4 deletions

BIN
anketa

Binary file not shown.

View File

@ -45,11 +45,16 @@ int add_student(struct student* students, const char* name, int votes){
int compare(const void* s1,const void* s2){
struct student* stud1=(struct student*)s1;
struct student* stud2=(struct student*)s2;
return stud1->votes==stud2->votes?0:stud1->votes<stud2->votes?1:-1;
if(stud1->votes==stud2->votes){
return 0;
}else if(stud1->votes<stud2->votes){
return 1;
}
return -1;
}
void sort_students(struct student* students){
qsort(students, count_students(students), sizeof(struct student), compare);
qsort(students,count_students(students),sizeof(struct student),compare);
}
void print_students(struct student* students){

BIN
anketa.o

Binary file not shown.

1
main.c
View File

@ -30,6 +30,7 @@ int main(int argc,char** argv){
case 'p': print_students(students);
break;
case 'o': sort_students(students);
print_students(students);
break;
case 'c': count_votes(students);
break;

BIN
main.o

Binary file not shown.

View File

@ -2,4 +2,9 @@ Anka
10
Marcel
30
Anka
5
Jozko
590
Anka
1000