Update 'cv2/program.c'

This commit is contained in:
Maryna Kravtsova 2020-10-21 14:48:39 +00:00
parent c7eaa87507
commit adc2849984

View File

@ -29,20 +29,14 @@ int read_pizza(struct pizza* item){
return 1; return 1;
} }
} }
int comparename(const void *a, const void *b){ int compare(const void *a, const void *b){
struct pizza* pizza_a = (void*) a; struct pizza* pizza_a = (void*) a;
struct pizza* pizza_b = (void*) b; struct pizza* pizza_b = (void*) b;
return strcmp(pizza_a->name, pizza_b->name);
}
int compareprize(const void *a, const void *b){
struct pizza* pizza_a = (void*) a;
struct pizza* pizza_b = (void*) b;
float r = (pizza_a->prize > pizza_b->prize) - (pizza_a->prize < pizza_b->prize); float r = (pizza_a->prize > pizza_b->prize) - (pizza_a->prize < pizza_b->prize);
if (r == 0){
r = strcmp(pizza_a->name, pizza_b->name);
}
return r; return r;
} }
@ -60,7 +54,7 @@ int main(){
counter++; counter++;
} }
qsort(jedalny_listok, counter, sizeof(struct pizza), compareprize); qsort(jedalny_listok, counter, sizeof(struct pizza), compare);
int i = 0; int i = 0;
for(i = 0; i < counter; i++){ for(i = 0; i < counter; i++){
@ -68,7 +62,5 @@ int main(){
printf("%f", jedalny_listok[i].prize); printf("%f", jedalny_listok[i].prize);
printf("\n"); printf("\n");
} }
return 0; return 0;
} }