// File: svector1.cpp // // Simple use of STL vector container class // Derives SortedVector class from vector // #include #include #include using namespace std ; template class SortedVector : public vector { public: void add(T x) ; } ; template void SortedVector::add(T x) { typename SortedVector::iterator it ; it = this->begin() ; while ( it != this->end() ) { if (! (x < *it) ) { break ; } it++ ; } insert(it,x) ; } int main() { SortedVector V ; V.add("George Washington") ; V.add("John Adams") ; V.add("Thomas Jefferson") ; V.add("James Madison") ; V.add("James Monroe") ; V.add("John Quincy Adams") ; V.add("Andrew Jackson") ; V.add("Martin Van Buren") ; V.add("William Henry Harrison") ; V.add("John Tyler") ; V.add("James Knox Polk") ; V.add("Zachary Taylor") ; V.add("Millard Fillmore") ; V.add("Franklin Pierce") ; V.add("James Buchanan") ; V.add("Abraham Lincoln") ; V.add("Andrew Johnson") ; V.add("Ulysses Simpson Grant") ; V.add("Rutherford Birchard Hayes") ; V.add("James Abram Garfield") ; V.add("Chester Alan Arthur") ; V.add("Grover Cleveland") ; V.add("Benjamin Harrison") ; V.add("Grover Cleveland") ; V.add("William McKinley") ; V.add("Theodore Roosevelt") ; V.add("William Howard Taft") ; V.add("Woodrow Wilson") ; V.add("Warren Gamaliel Harding") ; V.add("Calvin Coolidge") ; V.add("Herbert Clark Hoover") ; V.add("Franklin Delano Roosevelt") ; V.add("Harry S. Truman") ; V.add("Dwight David Eisenhower") ; V.add("John Fitzgerald Kennedy") ; V.add("Lyndon Baines Johnson") ; V.add("Richard Milhous Nixon") ; V.add("Gerald Rudolph Ford") ; V.add("James Earl Carter") ; V.add("Ronald Wilson Reagan") ; V.add("George Herbert Walker Bush") ; V.add("William Jefferson Clinton") ; V.add("George Walker Bush") ; SortedVector::iterator it ; for(it = V.begin() ; it != V.end() ; it++) { cout << *it << "\n" ; } }