diff --git a/cv2/program.c b/cv2/program.c index e4ad9a0..fe26dbb 100644 --- a/cv2/program.c +++ b/cv2/program.c @@ -9,6 +9,9 @@ struct pizza{ float prize; }; +//read the name and prize +//push them to stack + int read_pizza(struct pizza* item){ char line1[LINESIZE]; @@ -29,12 +32,15 @@ int read_pizza(struct pizza* item){ return 1; } } + +//compare 2 elements + int compare(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); - if (r == 0){ + if (r == 0){ //if prizes are identical, than check if names are in alphabetical order r = strcmp(pizza_a->name, pizza_b->name); } return r; @@ -48,12 +54,13 @@ int main(){ struct pizza item; int counter = 0; + //write menu to array while(stdin, read_pizza(&item)){ strcpy(jedalny_listok[counter].name, item.name); jedalny_listok[counter].prize = item.prize; counter++; } - + qsort(jedalny_listok, counter, sizeof(struct pizza), compare); int i = 0;