debug compare function
This commit is contained in:
parent
c7673f34d3
commit
ca874baf8d
@ -5,7 +5,7 @@
|
||||
|
||||
|
||||
#define SIZE 100
|
||||
#define NAMESIZE 30
|
||||
#define NAMESIZE 50
|
||||
|
||||
|
||||
|
||||
@ -22,11 +22,17 @@ int compare_name(const void* c1, const void* c2){
|
||||
|
||||
}
|
||||
|
||||
int compare_price(const void* c1, const void* c2){
|
||||
int compare_float(const void* c1, const void* c2){
|
||||
struct menu* p1 = (struct menu* ) c1;
|
||||
struct menu* p2 = (struct menu* ) c2;
|
||||
return p1->price - p2->price;
|
||||
|
||||
struct menu* p2 = (struct menu* ) c2;
|
||||
if( p1->price > p2->price ){
|
||||
return 1;
|
||||
}else if( p1->price < p2->price ){
|
||||
return -1;
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main(){
|
||||
@ -57,7 +63,7 @@ int main(){
|
||||
}
|
||||
|
||||
qsort(food_database,meal_counter,sizeof(struct menu),compare_name);
|
||||
qsort(food_database,meal_counter,sizeof(struct menu),compare_price);
|
||||
qsort(food_database,meal_counter,sizeof(struct menu),compare_float);
|
||||
for(int i=0; i<meal_counter; i++){
|
||||
printf("%s",food_database[i].name);
|
||||
printf("%f\n",food_database[i].price);
|
||||
|
Loading…
Reference in New Issue
Block a user