//Demonstration of a linked list Element after Scansholm Chapter 13.1 Pages 470-475 #include #include using namespace std; class Element{ public: Element *next; int data; Element( Element *n, int d): next(n), data(d){} void debug(){ cerr << (unsigned int)this << ":Element[next="<<(unsigned int)next<<", data=" << data << "]\n"; } }; void print(Element *first) { if(first) { for(Element * p = first; p!=NULL; p=p->next) p->debug(); }else{ cerr << "NULL\n"; } cerr << "---------------\n"; } void wait() { cout << "?"; cin.get(); } int main() { Element * first =0; print(first); wait(); first = new Element(first, 5); print(first); wait(); first = new Element(first, 3); print(first); wait(); first = new Element(first, 4); print(first); wait(); first = new Element(first, 42); print(first); }