#include #include #include //for class list #include //for the lower bound function using namespace std; //Store the incoming integers in a standard library list object, //in order of increasing size. int main() { list li; //born empty, but capable of holding ints. for (;;) { cout << "Input an int (or control-d when done): "; int i {0}; cin >> i; if (!cin) { //if the user typed control-d, break; //out of the for loop } //Let it be the correct position in which to insert i. auto it {lower_bound(begin(li), end(li), i)}; //Insert i into the list in front of position it. li.insert(it, i); } //Arrive here when the user typed control-d. cout << "\n"; cout << "Here are the ints you typed in:\n"; //Print all the integers. for (auto i: li) { cout << i << "\n"; } return EXIT_SUCCESS; //Nothing we have to remember to delete. }