Sudaobo Sudaobo@21cn.com There are two types: ----------------------------------- -------------------------------- Template
Example 2:
-------------------------------------------------- ------------------------------------
// tmp1.cpp: defines the entry point for the console application.//
#include "stdafx.h" #include
Using namespace std;
Class myless {
PUBLIC: BOOL Operator () (Const Int & a, Const Int & b) {Return A
INT Main (int Argc, char * argv []) {Vector Return 0;} Example 3: -------------------------------------------------- ---------------------- // tmp1.cpp: defines the entry point for the console application.// #include "stdafx.h" #include Using namespace std; TYPEDEF STRUCT; STRING LAST; Bool Sortbyfirst (Const Name & N1, Const Name & n2) {return (n1.first Bool Sortbylast (Const Name & N1, Const Name & n2) {return (n1.last INT main (int Argc, char * argv []) {Vector Tmp.first = "zhao"; tmp.last = "yun"; Contacts.push_back (TMP); Tmp.first = "gun"; tmp.last = "="; contacts.push_back (tmp); Tmp.first = "zhang"; tmp.last = "fei"; Contacts.push_back (TMP); COUT << "by first:" << endl; Sort (Contacts.Begin (), Contacts.end (), Sortbyfirst); For (j = contacts.begin (); j! = contacts.end (); j ) {cout << j-> first << "<< j-> last << endl;} Cout << "by last:" << Endl; Sort (Contacts.Begin (), Contacts.end (), Sortbylast;