#include #include class Node { friend ostream &operator<<(ostream&, const *Node); public: int data; Node* next; }; ostream &operator<<(ostream& output, const Node *n) { output << " [ " << n->data << " ] -> "; if (n->next == NULL) output << "||"; return output; } void PrintList (Node* t) { while (t != NULL) { cout << t; t = t->next; } cout << endl; } void main(void) { Node* h; Node* t; h = new Node; h->data = 42; h->next = new Node; t = h->next; t->data = 59; t->next = new Node; t = t->next; t->data = 109; t->next = new Node; t = t->next; t->data = 3; t->next = new Node; t = t->next; t->data = 255; t->next = NULL; PrintList(h); // deletes the second node in the list // remember -- we've got to do memory deallocation t = h->next; h->next = h->next->next; delete t; PrintList(h); // deletes the second node in the list // remember -- we've got to do memory deallocation t = h->next; h->next = h->next->next; delete t; PrintList(h); cout << endl; }