11299 - Lab6_hint   

Description

specification of qsort :

qsort ( A , N , sizeof(Obj) , compare_function);

1. A is an array containing items you want to sort.

2.  N is an integer , indicating how many items you want to sort.

3.  If A is an array containing integers , you should fill in "sizeof(int)"  as 3rd argument.

     If A is an array containing many "Product" , you should fill in "sizeof(Product)" as 3rd argument

     ※Product can be a struct defined by anybody. 

4. If you define a struct called "Product".

typedef struct

{

    int Price;

    int Size;

} Product;

 You should implement the compare_function like this:

 int compare_function1(const void *a, const void *b){

    Product *c,*d;
    c = (???) a;
    d = (???) b;

      if(..............) return -1; // Higher priority

     else if (.................) return 1; // Lower priority 

}

 

5. You may use "strcmp(name1,name2)" :

   If name1 have higher priority , the function will return -1.

   If name1 == name2 , the function will return 0.

   If name 2 have higher priority , the function will return 1.

    

Input

Output

Sample Input  Download

Sample Output  Download

Tags




Discuss