37typedef std::map<std::string, long, std::less<std::string>,
38 std::allocator<std::pair<const std::string, long> > >
friendMap;
39typedef std::map<long, std::string, std::less<long>,
40 std::allocator<std::pair<const long, std::string> > >
sortedMap;
48 std::cout << entry.first <<
":" << entry.second << std::endl;
54 std::cout << entry.first <<
":" << entry.second << std::endl;
59 return entry.second / 10000;
82 database[
name] = number;
85 database.erase (
name);
91 std::for_each (database.begin (), database.end (),
printEntry);
102 std::cout <<
"Listing for prefix " << pfx << std::endl;
105 where = std::find_if (database.begin (), database.end (),
107 while (where != database.end ()) {
109 where = std::find_if (++where, database.end (),
checkPrefix (pfx));
112 std::cout <<
"end of prefix listing" << std::endl;
118 std::cout <<
"Display by prefix" << std::endl;
121 for (friendMap::iterator
i = database.begin ();
i != database.end ();
i++)
122 sortedData.insert (sortedMap::value_type ((*i).second, (*i).first));
125 std::cout <<
"end display by prefix" << std::endl;
131 std::cout <<
"Telephone Directory sample program" << std::endl;
134 friends.
addEntry (
"Samantha", 6342343);
135 friends.
addEntry (
"Brenda", 5436546);
137 friends.
addEntry (
"Allen", 6348723);
142 std::cout <<
"End of telephone directory sample program" << std::endl;
bool operator()(const entry_type &entry)
void update(std::string name, long number)
void remove(std::string name)
void addEntry(std::string name, long number)
sortedMap::value_type sorted_entry_type
std::map< long, std::string, std::less< long >, std::allocator< std::pair< const long, std::string > > > sortedMap
void printEntry(const entry_type &entry)
void printSortedEntry(const sorted_entry_type &entry)
bool prefixCompare(const entry_type &a, const entry_type &b)
long prefix(const entry_type &entry)
std::map< std::string, long, std::less< std::string >, std::allocator< std::pair< const std::string, long > > > friendMap
friendMap::value_type entry_type