+ 3

How to clearly understand linked list in C++?

Mean how we can use it ?

22nd Mar 2021, 6:50 AM
Ahmad Khan
Ahmad Khan - avatar
3 Réponses
+ 2
If you just want to use a linked list in c++, I would use c++'s list class from the standard template library(stl) instead of creating one. More detail on it is at: https://docs.microsoft.com/en-us/cpp/standard-library/list-class?view=msvc-160 The main reason linked lists are explained in computer science courses is to teach you about pointers, data structures, and memory management. The best way to clearly understand how they work is to implement various operations on them and thoroughly test that your operations work. These operations can be things like: - Add value to beginning/head of list - Add value to end/tail of list - Add at a specified integer index into the list. - Delete value at end of list. - Delete value at beginning of the list - Delete value at arbitrary index into the list. - Check if a given value is found in the list. - Print all elements in the list using a loop. - Print all elements using recursion - free up all memory in the list in a destructor. This would include freeing memory for each and every node. Reimplement those operations on both a singly linked list and a doubly linked list. Implement the operations using only a head pointer. Reimplement the operations using both a head and a tail pointer. Most practically used linked lists are doubly linked lists with both head and tail pointers maintained but practicing with the above variations should improve understanding.
22nd Mar 2021, 8:31 AM
Josh Greig
Josh Greig - avatar
+ 1
Thank you Thanks a lot.
23rd Mar 2021, 2:35 PM
Ahmad Khan
Ahmad Khan - avatar