/* Filename: list.cpp Author: Br. David Carlson Date: June 29, 1999 Last Revised: December 23, 2001 This program adds some characters to the end of a list and then prints the list in two different ways. Tested with: Microsoft Visual C++ 6.0 Microsoft Visual C++ .NET g++ under Linux */ #include #include #include using namespace std; // Function prototypes: template void PrintA(list & L); void PrintB(list & L); int main(void) { list L; L.push_back('A'); L.push_back('B'); L.push_back('C'); PrintA(L); PrintB(L); return 0; } /* Given: L A list containing items of type T. Task: To print out the contents of list L. Return: Nothing. */ template void PrintA(list & L) { list::iterator p; cout << "Contents of list:" << endl; for (p = L.begin(); p != L.end(); p++) cout << *p << " "; cout << endl << endl; } /* Given: Item A character item. Task: To print out Item. Return: Nothing. */ void PrintItem(char Item) { cout << Item << " "; } /* Given: L A list containing characters. Task: To print out the contents of list L. Return: Nothing. */ void PrintB(list & L) { cout << "Contents of list:" << endl; for_each(L.begin(), L.end(), PrintItem); cout << endl << endl; }