Batch - B Practical Test Question

Batch - B Practical Test Question
Batch - B Practical Test Question

Linked List using Python

class Node:
    def __init__(self,val):
        self.val = val
        self.next = None
    
    def printLL(self):
        node = self 
        while node != None:
            print(node.val,"->") 
            node = node.next
            
    def insertNode(self, newNode):
        node = self 
        if(node.next==None):
            node.next=newNode
        else:
            while node.next != None:
                node = node.next
            node.next=newNode


#CodeForExecution

n1 = Node(10)

n1.insertNode(Node(20))
n1.insertNode(Node(30))
n1.insertNode(Node(40))


n1.printLL()

Comments