This commit is contained in:
Peter Petrek 2021-10-14 23:53:24 +02:00
parent 924e6cea5b
commit 3e76694b5e
2 changed files with 17 additions and 12 deletions

Binary file not shown.

View File

@ -43,25 +43,30 @@ int main() {
helper++; helper++;
} }
counter2 = (counter2 / 2) - 1; counter2 = (counter2 / 2);
qsort(databaza, counter2,sizeof(struct jedlo),compare); qsort(databaza, counter2,sizeof(struct jedlo),compare);
while(counter2 >= 0){ for(int z=0; z<counter2; z++){
printf("%s", databaza[counter2].name); printf("%s", databaza[z].name);
printf("%f\n", databaza[counter2].price); printf("%f\n", databaza[z].price);
counter2--;
} }
} }
int compare(const void* p1,const void*p2){ int compare(const void* p1,const void*p2){
struct jedlo* s1=(struct jedlo*)p1; struct jedlo s1 = *(const struct jedlo*)p1;
struct jedlo* s2=(struct jedlo*)p2; struct jedlo s2 = *(const struct jedlo*)p2;
if(s1->price == s2->price){ int order;
return 0;
if(s1.price > s2.price){
order = 1;
} }
else if(s1->price < s2->price){ else if(s1.price < s2.price){
return 1; order = -1;
} }
return -1; else {
order = 0;
}
return order;
} }