Click on hire.cpp to get source.
// File: C++Examples/Lists/hire.C
#include "prof.h"
#include <algorithm>
int PROFLIST::hire(const PROF& goodprof)
{// insert goodprof in alphabetic order;
// returns: 0 if successful, 1 if goodprof already there,
// -1 if no more memory
bool found; // note: C++ supports both C type truths and the type bool
iterator p = lower_bound(begin(), end(), goodprof);
// STL search using PROF::operator<
// on doubly linked lists, binary search performs fewer comparisions
// than a sequential search.
// returns the first valid place to insert goodprof and preserve order
// concept demo'd: STL lower_bound algo
// use the lower_bound member function for associative containers (sets)
//*** iterator p = lower_bound(goodprof);
if (p == end()) found = false;
else if (*p == goodprof) found = true;
else found = false;
if(found) return 1; // already there
if( size() == max_size() ) return -1; // out of memory
// max_size is how large the list can get at most
insert(p, goodprof); // STL insertion into the list<PROF>
// concept demo'd: STL insert
return 0;
} // end PROFLIST::hire