#include #include #include #include "node.h" using namespace std; void my_new_handler(); const char *progname; //uninitialized variable int main(int argc, char **argv) { progname = argv[0]; set_new_handler(my_new_handler); node *first = 0; //List initially empty. node *last = 0; cout << "Type a series of integers, EOF (control-d) to quit.\n"; value_type i; while (cin >> i) { //while (cin.operator>>(i).operator void *()) { node *const n = new node(i); if (first == 0) { //Insert n into an empty list. first = last = n; continue; } if (i <= *first) { //if (i <= (*first).operator value_type()) { n->insert_this_before(first); first = n; continue; } if (i > *last) { n->insert_this_after(last); last = n; continue; } node *p = first; for (; i > *p; p = p->next) { //i > (*p).operator value_type(); } n->insert_this_before(p); } cout << "\nHere are the integers in increasing order:\n"; for (const node *p = first; p;) { cout << *p << "\n"; //cout << (*p).operator value_type() << "\n"; const node *const doomed = p; p = p->next; delete doomed; } return cin.rdstate() == (ios_base::eofbit | ios_base::failbit) ? EXIT_SUCCESS : EXIT_FAILURE; } void my_new_handler() { cerr << progname << ": out of store\n"; exit(EXIT_FAILURE); }