/*TJ BiddleM 03719432CS2May 27, 2011Assignment 7*/#include <list>#include <queue>#include <iostream>#include <fstream> 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<string> > qOfLists; // Variable Declarations. fstream Bible; string line; list<string>::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<string>. list<string>bibleLines; 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<string> temp1 = qOfLists.front(); qOfLists.pop(); list<string> 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;}