class LinkedList { public: LinkedList(); ~LinkedList(); // destructor needed bool isEmpty(); int length(); void insert(int position, Item item); Item delete(int position); Item get(int position); private: ListNode * head; }; Notice that there isn't anything profoundly different about this definition. The difference is simply that the language gives us direct support for the concept that was implicit in the C-style ADT.
It can be useful to have "housekeeping" information in the the list class:
One can use an entire dummy node as the head, rather than simply a pointer:
This can eliminate some special cases in the insert/delete code. Often the memory overhead of having a node instead of a pointer is negligible.
The list type we have defined uses "internal" data for its nodes. Often one defines "external" data instead: