Here is an example of how to use std::sort: ------------------------------------------- #include #include #include using namespace std; // Our data. struct Blah { Blah(int Type, const char* pName) : m_Type(Type), m_pName(pName) { } int m_Type; const char* m_pName; }; // Print out a blah. ostream& operator<<(ostream& s, const Blah& b) { s << "Type: " << b.m_Type << ", Name: \"" << b.m_pName << "\""; return s; } // Sort functors. struct SortByType { bool operator()(const Blah& l, const Blah& r) const { return l.m_Type < r.m_Type; } }; struct SortByName { bool operator()(const Blah& l, const Blah& r) const { return strcmp(l.m_pName, r.m_pName) < 0; } }; struct SortByTypeThenName { bool operator()(const Blah& l, const Blah& r) const { return SortByType()(l, r) | (!SortByType()(r, l) && SortByName()(l, r)); } }; // The data. Blah g_Blahs[] = { Blah(1, "George"), Blah(2, "Liam"), Blah(2, "Hank"), Blah(0, "Abigail"), Blah(1, "Bob"), Blah(0, "Jessica"), Blah(2, "Con"), Blah(1, "Kyle"), Blah(0, "Faye") }; int main(int argc, char* argv[]) { Blah* pBegin = &g_Blahs[0]; Blah* pEnd = &g_Blahs[sizeof(g_Blahs)/sizeof(g_Blahs[0])]; ostream_iterator oi(cout, "\n"); // Sort by type. cout << "Type:\n"; sort(pBegin, pEnd, SortByType()); copy(pBegin, pEnd, oi); cout << "\n"; // Sort by name. cout << "Name:\n"; sort(pBegin, pEnd, SortByName()); copy(pBegin, pEnd, oi); cout << "\n"; // Sort by type and name. cout << "Type and name:\n"; sort(pBegin, pEnd, SortByTypeThenName()); copy(pBegin, pEnd, oi); cout << "\n"; return 0; } Steve