// // list.cpp -- how do I use a list? // #include #include using namespace std; void main() { cout << "\n Testing Basic List Operations " << "\n ===============================\n\n"; list li; cout << " pushing back " << 0.5 << ", " << 0.75 << ", " << 1.00 << ", and " << 1.25 << "\n"; li.push_back(0.50); // push-back operation will silently li.push_back(0.75); // allocate memory as needed to hold the li.push_back(1.00); // push_back entries li.push_back(1.25); cout << "\n the list length is " << li.size() << "\n" << " it contains the elements "; list::iterator it; for(it=li.begin(); it!=li.end(); it++) cout << *it << " "; // interatopm is only defined over the size cout << "\n\n"; // of the list after entries are made cout << " changing the 2nd element to 2.00:\n"; it = li.begin(); ++it; *it = 2.00; cout << " its elements are now "; for(it=li.begin(); it!=li.end(); it++) cout << *it << " "; cout << "\n\n"; cout << " inserting " << 13.6 << " after the second element:\n"; it = li.begin(); ++it; ++it; li.insert(it,13.6); cout << " its elements are now "; for(it=li.begin(); it!=li.end(); it++) cout << *it << " "; cout << "\n\n"; // cout << " inserting " << -7.2 << " at beginning:\n"; it = li.begin(); li.insert(it,-7.2); cout << " its elements are now "; for(it=li.begin(); it!=li.end(); it++) cout << *it << " "; cout << "\n\n"; cout << " inserting " << -22.2 << " after the last element:\n"; it = li.end(); li.insert(it,-22.2); cout << " its elements are now "; for(it=li.begin(); it!=li.end(); it++) cout << *it << " "; cout << "\n\n"; }