what are node types in python

 There are situations when the allocation of memory to store the data cannot be in a continuous block of memory. So we take help of pointers where the along with the data, the address of the next location of data element is also stored.

So we know the address of the next data element from the values of current data element. In general such structures are known as pointers. But in Python we refer them as Nodes.


Nodes are the foundations on which various other data structures linked lists and trees can be handled in python.


Creation of Nodes


The nodes are created by implementing a class which will hold the pointers along with the data element. In the below example we create a class named daynames to hold the name of the weekdays. The nextval pointer is initialized to null and three nodes and initialized with values as shown.

Traversing the Node Elements


We can traverse the elements of the node created above by creating a variable and assigning the first element to it. Then we use a while loop and nextval pointer to print out all the node elements. Note that we have one more additional data element and the nextval pointers are properly arranged to get the output as a days of a week in a proper sequence.

Comments