std::list

C++ has a built-in template class that implements the Doubly Linked List. Since then, it also contains all of the operations that the DoublyLinkedList data type has. Don't forget to include the list header at the beginning of code file if we are going to use the std::list data type. The usage of the iterator is also the same as the vector data type. We will refactor our code in the main.cpp file of the Doubly_Linked_List.cbp project so that we can use the list data type. The code should be as follows:

int main(){    // Initialize a linked list    list<int> linkedList;    // 43->NULL    linkedList.push_front(43);    // 76->43->NULL    linkedList.push_front(76);    // 76->43->15->NULL    linkedList.push_back(15);    // 76->43->15->44->NULL linkedList.push_back(44); ...

Get C++ Data Structures and Algorithms now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.