inked lists are perhaps the most widely used data structure. Yet writing a linked list from scratch is an arduous task. In a previous 10-Minute Solution
, you learned how to implement a linked list from scratch. A DIY solution may be useful for students and hackers who wish to study the internals of this data structure. However, in real-world production systems, using homemade lists is rarely a good idea. For starters, expensive time is wasted in debugging and optimizing them. Secondly, every programmer introduces individual variations and improvisations that turn into a maintenance nightmare. Finally, homemade solutions don't support generic programming very well. Often, they are confined to a single datatype.
How do you avoid the unnecessary drudgery of writing a linked list from scratch while benefiting from a generic, efficient and portable list data structure?
Instead of reinventing the wheel every time anew, use the STL std::list container class. Its uniform interface, generic nature and seamless integration with other STL constructs make it a superior choice to any homemade or MFC list class.