Python Linked list implementation I - insert

Published: 17 October 2019
on channel: TheMomentZone
2,053
0

Python Linked list implementation I - insert

In this video, I will start the linked list implementation from scratch.

So, first of all, let's create a distinct class for the nodes in the linked list. It's going to have the class Node with read object. This is how we create a class in Python, and we are going to have a constructor, so we define the init method. Basically, this is how we represent the constructor in python with the self and the data, whenever we instantiate a node we are going to specify the data we would like to store in this node. Every node is going to store the data itself and going to store a reference to the next node.

Then we have the linked list class with the object. We have the init constructor with the self, and basically, we are going to create the head of the linked list.

That's all about the head and the size and we are going to have a method, for example, insert start is going to insert some data at the beginning of the list. So, first of all, we have to increment the size so self.size plus 1. We just increment the size, and then we have to instantiate, and newNode it's going to be a node with the data. This is how we instantiate a class in Python.

Thanks for watching!


On this page of the site you can watch the video online Python Linked list implementation I - insert with a duration of hours minute second in good quality, which was uploaded by the user TheMomentZone 17 October 2019, share the link with friends and acquaintances, this video has already been watched 2,053 times on youtube and it was liked by 0 viewers. Enjoy your viewing!