Table Of Contents
* 🤓 INTRODUCTION
* 🟢 CREATING A NODE
* 🔗CREATING THE LINKED LIST
* 😉ADD ELEMENT TO THE HEAD OF THE LIST
* 🐈ADD ELEMENT TO THE TAIL OF THE LIST
* 🔁CREATE A LINKED LIST FROM AN ARRAY
* ❌DELETING ELEMENTS FROM A LIST
* ❌DELETE HEAD
* ✅CHECK IF AN ELEMENT WITH SPECIFIC VALUE IS IN THE LIST
* 🙏 THANK YOU
Welcome, my dear hackers!🚀 Welcome to yet another blog article about elementary data structures.
If you missed the previous article where we describe the Linked Lists and write pseudocode, you can check it out here:
Since we are creating a Singly-Linked list, I am going to name the class "SLList". The class has a couple of class member variables and those are length (or size) of the list, a pointer to the head of the list, a pointer to the tail of the list.
Let's assume that our user wants to provide an array of elements, but it is required from us to convert that array into the linked list in the respective order. We will do it like this:
- Check if the provided value is an array
- If it is, we call a member function that will traverse an array and call our addToHead function. I will omit some code so that we can display a nice image.
This is the most complex function that we will implement. This function needs to differentiate if we were to delete the first (head), the last (tail), or any other element with the specified value. But, we will also provide an indicator that will override the function to delete the first element it encounters with the specified value.
And finally our code!
Please leave a comment, tell me about you, about your work, comment your thoughts, connect with me!
Have a nice time hacking! 😊