Introduction to Linkedlist
Putta Hemanth Kumar
Software Developer @ Samsung Research Institute || Code and Content || IIEST || DSA || C++ || System Design || 1.5K LinkedIn
Ram has completed his learning and practice in array data structure, He understood all the pros and cons of arrays, Now he wanted to learn LinkedLists which is a dynamic data structure. While he was wondering why this new data structure was invented in the first place.
Ram continued doing some other programming problems, while solving various problems Ram encountered some situations where he was not sure how much array space to be declared prior. Ram was in a dilemma what If I declare more space but the code can use significantly less, or declare less space for an array but the code takes more space?
Ram understood arrays were not just sufficient and he need to learn another data structure to solve the remaining questions. While ram thinking regarding this, he listed out all the different problems he’s facing while using arrays ….
After thinking of various other issues he’s facing while using arrays, Ram got fed up and opened the book to see what are these linked lists.
To his surprise, Ram is reading all the solutions for the issues with arrays, as he started to learn, He understood that just like any long object is divided and stored at home like if any long vegetable is unable to fit in the refrigerator, his mom just cuts and stores at two parts. Similarly when we wanted to declare a long space of similar datatypes and not sure of memory, this LinkedList helps a lot.
Every data block of the linked list is called a Node which is divided into 2 parts consisting of data and the address of the following Node. And the best thing about this data structure is that you can add any number of nodes at any point at his will and he can remove any number of nodes without the tension of shifting numbers, all these happen with the game of addresses.
领英推荐
Ram, understood the theory of what a linked list is, but he knows that there is a user-defined datatype he learned namely struct and class, So he can take any datatype which has two variables data of integer type and address of another structure or class.
Ram understood that this data structure is like a connected cycle chain where he has the address of the head only, the remaining blocks are stored somewhere in the memory and he can only access the next block with the address he’s holding in the current block.
?The linked list is like the above cycle chain, you can just open the link between any two chain pieces and you can change the piece, add more pieces to increase the length, or remove more pieces to decrease the length.
Learn more about linked lists from below link
Happy Learning and Happy Coding, If you find this article helpful please do like, share, and comment your views.