/* * Simple-minded test program to demonstrate the use of the * integer-list iterator. We push our arguments onto a list of * integers, and then use the iterator to print them in order. * Because of the way we pushed them, the print order will be * reversed. * * Note: Normally, iterators should be defined together with the * appropriate data structures. One should not have to separately * include "intlistiter.hh". Instead, when one includes * "templatelist.hh", the iterator should be automatically defined. I * have done it this way only because the list class was provided in a * previous handout, and I don't want to repeat it. */ #include "intlistiter.hh" #include "templatelist.hh" #include #include /* * Table of contents: */ int main(int argc, char* argv[]); // Test the integer-list iterator int main( int argc, // Argument count char* argv[]) // Argument vector { /* * Build a list with all the arguments in reverse order */ List argList; for (int i = 1; i < argc; i++) { int j = atoi(argv[i]); // Temp needed for push argList.push(j); } /* * Iterate through the list, printing arguments */ for (IntListIterator i(argList); i; i++) cout << *i << ' '; cout << endl; /* * Change the third argument to a 7 */ if (argc >= 4) { IntListIterator i(argList); for (int j = 1; j < argc; i++, j++) { if (j == 3) *i = 7; } } /* * Iterate through the list, printing arguments again */ for (IntListIterator i(argList); i; i++) cout << *i << ' '; cout << endl; return 0; }