Squareroot ( n ) | Python3 program to find sqrt ( n ) 'th node  of a linked list  Node class  ; Function to initialise the node object ; Function to get the sqrt ( n ) th node of a linked list ; Traverse the list ; check if j = sqrt ( i ) ; for first node ; increment j if j = sqrt ( i ) ; return node 's data  ; function to add a new node at the beginning of the list ; allocate node ; put in the data ; link the old list off the new node ; move the head to point to the new node ; Driver Code ; Start with the empty list
class Node : NEW_LINE INDENT def __init__ ( self , data ) : NEW_LINE INDENT self . data = data NEW_LINE self . next = None NEW_LINE DEDENT DEDENT def printsqrtn ( head ) : NEW_LINE INDENT sqrtn = None NEW_LINE i = 1 NEW_LINE j = 1 NEW_LINE while ( head != None ) : NEW_LINE INDENT if ( i == j * j ) : NEW_LINE INDENT if ( sqrtn == None ) : NEW_LINE INDENT sqrtn = head NEW_LINE DEDENT else : NEW_LINE INDENT sqrtn = sqrtn . next NEW_LINE DEDENT j = j + 1 NEW_LINE DEDENT i = i + 1 NEW_LINE head = head . next NEW_LINE DEDENT return sqrtn . data NEW_LINE DEDENT def print_1 ( head ) : NEW_LINE INDENT while ( head != None ) : NEW_LINE INDENT print ( head . data , end = " ▁ " ) NEW_LINE head = head . next NEW_LINE DEDENT print ( " ▁ " ) NEW_LINE DEDENT def push ( head_ref , new_data ) : NEW_LINE INDENT new_node = Node ( 0 ) NEW_LINE new_node . data = new_data NEW_LINE new_node . next = ( head_ref ) NEW_LINE ( head_ref ) = new_node NEW_LINE return head_ref NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT head = None NEW_LINE head = push ( head , 40 ) NEW_LINE head = push ( head , 30 ) NEW_LINE head = push ( head , 20 ) NEW_LINE head = push ( head , 10 ) NEW_LINE print ( " Given ▁ linked ▁ list ▁ is : " ) NEW_LINE print_1 ( head ) NEW_LINE print ( " sqrt ( n ) th ▁ node ▁ is ▁ " , printsqrtn ( head ) ) NEW_LINE DEDENT