From b51f1cd5674ca73e3a07eae2d5968c1ac238a34d Mon Sep 17 00:00:00 2001 From: Yurii Yakovenko Date: Mon, 7 Oct 2024 19:49:07 +0000 Subject: [PATCH] Update cv2/program.c --- cv2/program.c | 124 ++++++++++++++++++++++++++++---------------------- 1 file changed, 69 insertions(+), 55 deletions(-) diff --git a/cv2/program.c b/cv2/program.c index 85aa1bf..b2762f9 100644 --- a/cv2/program.c +++ b/cv2/program.c @@ -1,5 +1,6 @@ #include #include +#include #define LINE_SIZE 100 #define LIST_SIZE 200 @@ -7,68 +8,24 @@ struct pizza { char name[LINE_SIZE]; - float prize; + float prize; }; -int read_pizza_list(struct pizza* list); - -int compare_pizza (const void * a, const void * b) +int compare_pizza (struct pizza p1, struct pizza p2) { - struct pizza* p1=(struct pizza*)a; - struct pizza* p2=(struct pizza*)b; - - if( p1->prize > p2->prize ) + if( p1.prize > p2.prize ) { return 1; - } - - - if( p1->prize < p2->prize ) + } + + if( p1.prize < p2.prize ) { return -1; } - return strcmp(p1->name, p2->name); -} - - -int main() -{ - struct pizza list[LIST_SIZE]; - memset(list,0,LIST_SIZE*sizeof(struct pizza)); - - int n=read_pizza_list(list); - printf("%d",n); - for(int k=0; kname, 299, stdin); - }while(p!=NULL && p[0]=='\n'); - - if(p==NULL) {return 0;} - - st=scanf("%f", &r->prize); - - - - if(st==1) - {return 1;} - else - {return 0;} -} - - -int read_pizza_list(struct pizza* list) + return strcmp(p1.name, p2.name); +} + int read_pizza_list(struct pizza* list) { int counter = 0; for (int i=0; i< LIST_SIZE; i++) @@ -84,11 +41,68 @@ int read_pizza_list(struct pizza* list) } else { - break; } } return counter; +} + +void sort_pizza_list(struct pizza* list, int n) +{ + bool sorted; + struct pizza tmp; + + for(int k=0; k1) + { + tmp=list[i]; + list[i]=list[i+1]; + list[i+1]=tmp; + sorted=false; + } + } + if(sorted) + { + break; + } + } +} -} \ No newline at end of file +int main() +{ + struct pizza list[LIST_SIZE]; + memset(list,0,LIST_SIZE*sizeof(struct pizza)); + + int n=read_pizza_list(list); + + sort_pizza_list(&list,n); + + for(int k=0; kname, 299, stdin); + }while(p!=NULL && p[0]=='\n'); + + if(p==NULL) {return 0;} + + st=scanf("%f", &r->prize); + + if(st==1) + {return 1;} + else + {return 0;} +}