test
This commit is contained in:
parent
b83500591d
commit
c9a74987d0
9
anketa.c
9
anketa.c
@ -45,11 +45,16 @@ int add_student(struct student* students, const char* name, int votes){
|
|||||||
int compare(const void* s1,const void* s2){
|
int compare(const void* s1,const void* s2){
|
||||||
struct student* stud1=(struct student*)s1;
|
struct student* stud1=(struct student*)s1;
|
||||||
struct student* stud2=(struct student*)s2;
|
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){
|
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){
|
void print_students(struct student* students){
|
||||||
|
1
main.c
1
main.c
@ -30,6 +30,7 @@ int main(int argc,char** argv){
|
|||||||
case 'p': print_students(students);
|
case 'p': print_students(students);
|
||||||
break;
|
break;
|
||||||
case 'o': sort_students(students);
|
case 'o': sort_students(students);
|
||||||
|
print_students(students);
|
||||||
break;
|
break;
|
||||||
case 'c': count_votes(students);
|
case 'c': count_votes(students);
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user