/* TJ Biddle M 03719432 CS2 May 27, 2011 Assignment 7 */ #include #include #include #include using namespace std; int main(int argc, char *argv[]) { // Check to make sure we were passed a filename. if (argv[1] == 0) { cout << "Please include a filename as an argument!" << endl; return 0; } // Create the queue that will hold the lists. queue< list > qOfLists; // Variable Declarations. fstream Bible; string line; list::iterator pos; // Open our file and check to make sure it has opened. Bible.open(argv[1], fstream::in | fstream::out); if ( !Bible.is_open() ) { cout << "File could not be opened." << endl; } // Do this as long as the fstream is good. while (Bible.good()) { // Read each line and store it into a list. listbibleLines; getline(Bible,line); bibleLines.push_back(line); qOfLists.push(bibleLines); } // Close our file. Bible.close(); // Do this as long as there are two lines to merge. while (qOfLists.size() >= 2) { // Store each line into a temporary variable, and then merge them. Add the merged list onto the queue. list temp1 = qOfLists.front(); qOfLists.pop(); list temp2 = qOfLists.front(); qOfLists.pop(); temp1.merge(temp2); qOfLists.push(temp1); } // Define the iterator and make sure to decrement to avoid a segmentation fault. pos = qOfLists.front().end(); pos--; // Iterate through the last 10 values in the list. for(int i=1; pos != qOfLists.front().begin() && i !=10; --pos, ++i) { cout << *pos << endl; } return 0; }