#include #include #include #include using namespace std; struct node { char c; int i; double d; node( char c, int i, double d ) : c(c), i(i), d(d) {} friend ostream& operator<<(ostream& os, const node& n); }; // node ostream& operator<<(ostream& os, const node& n) { return os << "c:" << n.c << " i:" << n.i << " d:" << n.d << endl; } template < class T > void printList( const list< T > &listRef ); list::iterator find(list::iterator b,list::iterator e, char c ) { list::iterator li = b; for (; li != e && li->c != c; ++li) {} return li; } int main() { list top; // create doubly linked list int i; for ( i = 0; i < 10; i += 1 ) { // create list nodes node n( 'a' + i, i, (double)i + 0.5 ); top.push_back( n ); // copy node at end of list } // for list::iterator li; // iterator for doubly linked list printList( top ); cout << endl; li = find( top.begin(), top.end(), 'd' ); if ( li != top.end() ) { cout << "found 'd' associated with node " << *li; } else { cout << "did not find node associated with 'd'" << endl; } cout << "erase list" << endl; top.clear(); printList( top ); } // main template < class T > void printList( const list< T > &listRef ) { if ( listRef.empty() ) { cout << "List is empty" << endl; } else { ostream_iterator< T > output( cout, "" ); copy( listRef.begin(), listRef.end(), output ); cout << endl; } // if } // printList