/* A link and a list are not the same thing. There are things that make sense to keep track of for a list that are meaningless for links, such as how long is the list, which is its last link. So link and list should not be represented by the same objects. */ class List { protected: struct Link { thing * data; Link * next; Link(thing * a, Link * b = NULL) { data = a; next = b; } }; Link * first; Link * last; // only add this if adding to the end is needed int length; // only add this if knowing the length is needed public: List(); void add_to_end(thing * x); void add_to_front(thing * x); thing * remove_from_front(); // removing from the end is still nasty int how_long(); }; List::List() { first = NULL; last = NULL; length = 0; } void List::add_to_front(thing * x) { /* to be seen */ length += 1; } void List::add_to_end(thing * x) { /* to be seen */ length += 1; } thing * List::remove_from_front() { if (front == NULL) return NULL; /* to be seen */ length -= 1; } int List::how_long() { return length; }