#include #include "Book.h" #include #include struct CompareByAuthor { bool operator() ( const Book& a, const Book& b ) const { return a.author() < b.author(); } }; struct CompareByTitle { bool operator() ( const Book& a, const Book& b ) const { return a.title() < b.title(); } }; int main() { cout << "esempio di ordinamento" << endl; Book b1 ( "Dante Alighieri", "La Divina Commedia" ); Book b2 ( "Alessandro Manzoni", "I promessi sposi" ); Book b3 ( "Erich Gamma et at.", "Design Patterns" ); vector v; v.push_back( b1 ); v.push_back( b2 ); v.push_back( b3 ); vector::const_iterator i; CompareByAuthor comp1; sort( v.begin(), v.end(), comp1 ); for( i = v.begin(); i != v.end(); i++ ) i->print(); cout << "----------------------------" << endl; CompareByTitle comp2; sort( v.begin(), v.end(), comp2 ); for( i = v.begin(); i != v.end(); i++ ) i->print(); return 0; }