Saturday, April 14, 2018

How to create a Python Node?


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.

The nextval pointer of node e1 points to e3 while the nextval pointer of node e3 points to e2.

class daynames:
    def __init__(self, dataval=None):
        self.dataval = dataval
        self.nextval = None

e1 = daynames('Mon')
e2 = daynames('Wed')
e3 = daynames('Tue')

e1.nextval = e3
e3.nextval = e2