c ++ sort-containing structure () structure in c ++ use sort () Sort

Reprinted from the structure of the sort c ++ () ordering

c ++ structural body sort () sorting 

// add the function header 
#include <algorithm> // definition of the structure Yoy 
typedef struct 
{ Double TotalPrice;          // Total Double Storage;            // Stock Double averageprice;   // average price } Toy; 
Toy Toy [ 1000 ]; // define the sort rule BOOL Compare (A Toy, Toy B) 
{ return a.averageprice> b.averageprice; 
} // <ascending> descending BOOL COMPARE 1 (A Toy, Toy B) 
{ IF (A .totalprice! =
 
 
 
 


b.totalprice) { return a.totalprice<b.totalprice; }else if(a.storage!=b.storage) { return a.storage<b.storage; }
int main() { ...... sort(toy,toy+N,compare); ...... }

 

 
 

Guess you like

Origin www.cnblogs.com/Theo-sblogs/p/11502671.html