codeparrot/xlcost-text-to-code huggingface dataset:
Rotate Linked List block wise | Link list node ; Recursive function to rotate one block ; Rotate Clockwise ; Rotate anti - Clockwise ; Function to rotate the linked list block wise ; If length is 0 or 1 return head ; If degree of rotation is 0 , return head ; Traverse upto last element of this block ; Storing the first node of next block ; If nodes of this block are less than k . Rotate this block also ; Append the new head of next block to the tail of this block ; Return head of updated Linked List ; Function to push a node ; Function to print linked list ; Driver code ; Start with the empty list ; Create a list 1.2 . 3.4 .5 . 6.7 . 8.9 . None ; k is block size and d is number of rotations in every block .
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 rotateHelper ( blockHead , blockTail , d , tail , k ) : NEW_LINE INDENT if ( d == 0 ) : NEW_LINE INDENT return blockHead , tail NEW_LINE DEDENT if ( d > 0 ) : NEW_LINE INDENT temp = blockHead NEW_LINE i = 1 NEW_LINE while temp . next . next != None and i < k - 1 : NEW_LINE INDENT temp = temp . next NEW_LINE i += 1 NEW_LINE DEDENT blockTail . next = blockHead NEW_LINE tail = temp NEW_LINE return rotateHelper ( blockTail , temp , d - 1 , tail , k ) NEW_LINE DEDENT if ( d < 0 ) : NEW_LINE INDENT blockTail . next = blockHead NEW_LINE tail = blockHead NEW_LINE return rotateHelper ( blockHead . next , blockHead , d + 1 , tail , k ) NEW_LINE DEDENT DEDENT def rotateByBlocks ( head , k , d ) : NEW_LINE INDENT if ( head == None or head . next == None ) : NEW_LINE INDENT return head NEW_LINE DEDENT if ( d == 0 ) : NEW_LINE INDENT return head NEW_LINE DEDENT temp = head NEW_LINE tail = None NEW_LINE i = 1 NEW_LINE while temp . next != None and i < k : NEW_LINE INDENT temp = temp . next NEW_LINE i += 1 NEW_LINE DEDENT nextBlock = temp . next NEW_LINE if ( i < k ) : NEW_LINE INDENT head , tail = rotateHelper ( head , temp , d % k , tail , i ) NEW_LINE DEDENT else : NEW_LINE INDENT head , tail = rotateHelper ( head , temp , d % k , tail , k ) NEW_LINE DEDENT tail . next = rotateByBlocks ( nextBlock , k , d % k ) ; NEW_LINE return head ; NEW_LINE DEDENT def push ( head_ref , new_data ) : NEW_LINE INDENT new_node = Node ( new_data ) 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 def printList ( node ) : NEW_LINE INDENT while ( node != None ) : NEW_LINE INDENT print ( node . data , end = ' ▁ ' ) NEW_LINE node = node . next NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT head = None NEW_LINE for i in range ( 9 , 0 , - 1 ) : NEW_LINE INDENT head = push ( head , i ) NEW_LINE DEDENT print ( " Given ▁ linked ▁ list ▁ " ) NEW_LINE printList ( head ) NEW_LINE k = 3 NEW_LINE d = 2 NEW_LINE head = rotateByBlocks ( head , k , d ) NEW_LINE print ( " Rotated by blocks Linked list   " ) NEW_LINE printList ( head ) NEW_LINE DEDENT
Check if two numbers are bit rotations of each other or not | function to check if two numbers are equal after bit rotation ; x64 has concatenation of x with itself . ; comapring only last 32 bits ; right shift by 1 unit ; Driver Code
def isRotation ( x , y ) : NEW_LINE INDENT x64 = x | ( x << 32 ) NEW_LINE while ( x64 >= y ) : NEW_LINE INDENT if ( ( x64 ) == y ) : NEW_LINE INDENT return True NEW_LINE DEDENT x64 >>= 1 NEW_LINE DEDENT return False NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT x = 122 NEW_LINE y = 2147483678 NEW_LINE if ( isRotation ( x , y ) == False ) : NEW_LINE INDENT print ( " yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " no " ) NEW_LINE DEDENT DEDENT
Count rotations divisible by 4 | Returns count of all rotations divisible by 4 ; For single digit number ; At - least 2 digit number ( considering all pairs ) ; Considering the number formed by the pair of last digit and 1 st digit ; Driver program
def countRotations ( n ) : NEW_LINE INDENT l = len ( n ) NEW_LINE if ( l == 1 ) : NEW_LINE INDENT oneDigit = ( int ) ( n [ 0 ] ) NEW_LINE if ( oneDigit % 4 == 0 ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT return 0 NEW_LINE DEDENT count = 0 NEW_LINE for i in range ( 0 , l - 1 ) : NEW_LINE INDENT twoDigit = ( int ) ( n [ i ] ) * 10 + ( int ) ( n [ i + 1 ] ) NEW_LINE if ( twoDigit % 4 == 0 ) : NEW_LINE INDENT count = count + 1 NEW_LINE DEDENT DEDENT twoDigit = ( int ) ( n [ l - 1 ] ) * 10 + ( int ) ( n [ 0 ] ) NEW_LINE if ( twoDigit % 4 == 0 ) : NEW_LINE INDENT count = count + 1 NEW_LINE DEDENT return count NEW_LINE DEDENT n = "4834" NEW_LINE print ( " Rotations : ▁ " , countRotations ( n ) ) NEW_LINE
Check if a string can be obtained by rotating another string 2 places | Function to check if string2 is obtained by string 1 ; Initialize string as anti - clockwise rotation ; Initialize string as clock wise rotation ; check if any of them is equal to string1 ; Driver code
def isRotated ( str1 , str2 ) : NEW_LINE INDENT if ( len ( str1 ) != len ( str2 ) ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( len ( str1 ) < 2 ) : NEW_LINE INDENT return str1 == str2 NEW_LINE DEDENT clock_rot = " " NEW_LINE anticlock_rot = " " NEW_LINE l = len ( str2 ) NEW_LINE anticlock_rot = ( anticlock_rot + str2 [ l - 2 : ] + str2 [ 0 : l - 2 ] ) NEW_LINE clock_rot = clock_rot + str2 [ 2 : ] + str2 [ 0 : 2 ] NEW_LINE return ( str1 == clock_rot or str1 == anticlock_rot ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT str1 = " geeks " NEW_LINE str2 = " eksge " NEW_LINE DEDENT if isRotated ( str1 , str2 ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT
Lexicographically minimum string rotation | Set 1 | This function return lexicographically minimum rotation of str ; Find length of given string ; Create an array of strings to store all rotations ; Create a concatenation of string with itself ; One by one store all rotations of str in array . A rotation is obtained by getting a substring of concat ; Sort all rotations ; Return the first rotation from the sorted array ; Driver Code
def minLexRotation ( str_ ) : NEW_LINE INDENT n = len ( str_ ) NEW_LINE arr = [ 0 ] * n NEW_LINE concat = str_ + str_ NEW_LINE for i in range ( n ) : NEW_LINE INDENT arr [ i ] = concat [ i : n + i ] NEW_LINE DEDENT arr . sort ( ) NEW_LINE return arr [ 0 ] NEW_LINE DEDENT print ( minLexRotation ( " GEEKSFORGEEKS " ) ) NEW_LINE print ( minLexRotation ( " GEEKSQUIZ " ) ) NEW_LINE print ( minLexRotation ( " BCABDADAB " ) ) NEW_LINE
Types of Linked List | structure of Node
class Node : NEW_LINE INDENT def __init__ ( self , data ) : NEW_LINE INDENT self . data = data NEW_LINE self . next = None NEW_LINE DEDENT DEDENT
Types of Linked List | structure of Node
class Node : NEW_LINE INDENT def __init__ ( self , data ) : NEW_LINE INDENT self . previous = None NEW_LINE self . data = data NEW_LINE self . next = None NEW_LINE DEDENT DEDENT
Remove all the Even Digit Sum Nodes from a Circular Singly Linked List | Structure for a node ; Function to insert a node at the beginning of a Circular linked list ; Create a new node and make head as next of it . ; If linked list is not None then set the next of last node ; Find the node before head and update next of it . ; Point for the first node ; Function to deltete the node from a Circular Linked list ; If node to be delteted is head node ; Traverse list till not found deltete node ; Copy the address of the node ; Finally , free the memory occupied by delt ; Function to find the digit sum for a number ; Function to deltete all the Even Digit Sum Nodes from the singly circular linked list ; Traverse the list till the end ; If the node ' s ▁ data ▁ is ▁ Fibonacci , ▁ ▁ deltete ▁ node ▁ ' ptr ; Point to the next node ; Function to print nodes in a given Circular linked list ; Driver code ; Initialize lists as empty ; Created linked list will be 9.11 .34 .6 .13 .21
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 push ( head_ref , data ) : NEW_LINE INDENT ptr1 = Node ( data ) NEW_LINE temp = head_ref NEW_LINE ptr1 . data = data NEW_LINE ptr1 . next = head_ref NEW_LINE if ( head_ref != None ) : NEW_LINE INDENT while ( temp . next != head_ref ) : NEW_LINE INDENT temp = temp . next NEW_LINE DEDENT temp . next = ptr1 NEW_LINE DEDENT else : NEW_LINE INDENT ptr1 . next = ptr1 NEW_LINE DEDENT head_ref = ptr1 NEW_LINE return head_ref NEW_LINE DEDENT def delteteNode ( head_ref , delt ) : NEW_LINE INDENT temp = head_ref NEW_LINE if ( head_ref == delt ) : NEW_LINE INDENT head_ref = delt . next NEW_LINE DEDENT while ( temp . next != delt ) : NEW_LINE INDENT temp = temp . next NEW_LINE DEDENT temp . next = delt . next NEW_LINE del ( delt ) NEW_LINE return NEW_LINE DEDENT def digitSum ( num ) : NEW_LINE INDENT sum = 0 NEW_LINE while ( num != 0 ) : NEW_LINE INDENT sum += ( num % 10 ) NEW_LINE num //= 10 NEW_LINE DEDENT return sum NEW_LINE DEDENT def delteteEvenDigitSumNodes ( head ) : NEW_LINE INDENT ptr = head NEW_LINE next = None NEW_LINE while True : NEW_LINE INDENT if ( not ( digitSum ( ptr . data ) & 1 ) ) : NEW_LINE INDENT delteteNode ( head , ptr ) NEW_LINE DEDENT next = ptr . next NEW_LINE ptr = next NEW_LINE if ( ptr == head ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT DEDENT def printList ( head ) : NEW_LINE INDENT temp = head NEW_LINE if ( head != None ) : NEW_LINE INDENT while True : NEW_LINE INDENT print ( temp . data , end = ' ▁ ' ) NEW_LINE temp = temp . next NEW_LINE if ( temp == head ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT head = None NEW_LINE head = push ( head , 21 ) NEW_LINE head = push ( head , 13 ) NEW_LINE head = push ( head , 6 ) NEW_LINE head = push ( head , 34 ) NEW_LINE head = push ( head , 11 ) NEW_LINE head = push ( head , 9 ) NEW_LINE delteteEvenDigitSumNodes ( head ) NEW_LINE printList ( head ) NEW_LINE DEDENT
Delete all odd nodes of a Circular Linked List | Python3 program to delete all odd node from a Circular singly linked list ; Structure for a node ; Function to insert a node at the beginning of a Circular linked list ; If linked list is not None then set the next of last node ; For the first node ; Delete the node if it is odd ; If node to be deleted is head node ; Traverse list till not found delete node ; Copy address of node ; Function to delete all odd nodes from the singly circular linked list ; if node is odd ; po to next node ; Function to pr nodes ; Driver code ; Initialize lists as empty ; Created linked list will be 56 -> 61 -> 57 -> 11 -> 12 -> 2
import math NEW_LINE 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 push ( head_ref , data ) : NEW_LINE INDENT ptr1 = Node ( data ) NEW_LINE temp = head_ref NEW_LINE ptr1 . data = data NEW_LINE ptr1 . next = head_ref NEW_LINE if ( head_ref != None ) : NEW_LINE INDENT while ( temp . next != head_ref ) : NEW_LINE INDENT temp = temp . next NEW_LINE DEDENT temp . next = ptr1 NEW_LINE DEDENT else : NEW_LINE INDENT ptr1 . next = ptr1 NEW_LINE DEDENT head_ref = ptr1 NEW_LINE return head_ref NEW_LINE DEDENT def deleteNode ( head_ref , delete ) : NEW_LINE INDENT temp = head_ref NEW_LINE if ( head_ref == delete ) : NEW_LINE INDENT head_ref = delete . next NEW_LINE DEDENT while ( temp . next != delete ) : NEW_LINE INDENT temp = temp . next NEW_LINE DEDENT temp . next = delete . next NEW_LINE DEDENT def deleteoddNodes ( head ) : NEW_LINE INDENT ptr = head NEW_LINE next = None NEW_LINE next = ptr . next NEW_LINE ptr = next NEW_LINE while ( ptr != head ) : NEW_LINE INDENT if ( ptr . data % 2 == 1 ) : NEW_LINE INDENT deleteNode ( head , ptr ) NEW_LINE DEDENT next = ptr . next NEW_LINE ptr = next NEW_LINE DEDENT return head NEW_LINE DEDENT def prList ( head ) : NEW_LINE INDENT temp = head NEW_LINE if ( head != None ) : NEW_LINE INDENT print ( temp . data , end = " ▁ " ) NEW_LINE temp = temp . next NEW_LINE while ( temp != head ) : NEW_LINE INDENT print ( temp . data , end = " ▁ " ) NEW_LINE temp = temp . next NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT head = None NEW_LINE head = push ( head , 2 ) NEW_LINE head = push ( head , 12 ) NEW_LINE head = push ( head , 11 ) NEW_LINE head = push ( head , 57 ) NEW_LINE head = push ( head , 61 ) NEW_LINE head = push ( head , 56 ) NEW_LINE print ( " List ▁ after ▁ deletion ▁ : ▁ " , end = " " ) NEW_LINE head = deleteoddNodes ( head ) NEW_LINE prList ( head ) NEW_LINE DEDENT
Insertion in a sorted circular linked list when a random pointer is given | Python3 implementation of the approach ; Node structure ; Function to create a node ; Function to find and return the head ; If the list is empty ; Finding the last node of the linked list the last node must have the highest value if no such element is present then all the nodes of the linked list must be same ; Return the head ; Function to insert a new_node in the list in sorted fashion . Note that this function expects a pointer to head node as this can modify the head of the input linked list ; If the list is empty ; If the node to be inserted is the smallest then it has to be the new head ; Find the last node of the list as it will be pointing to the head ; Locate the node before the point of insertion ; Return the new head ; Function to print the nodes of the linked list ; Driver code ; Start with an empty linked list ; Create linked list from the given array ; Move to a random node if it exists ; Print the contents of the created list
from random import randint NEW_LINE class Node : NEW_LINE INDENT def __init__ ( self ) : NEW_LINE INDENT self . next = None NEW_LINE self . data = 0 NEW_LINE DEDENT DEDENT def create ( ) : NEW_LINE INDENT new_node = Node ( ) NEW_LINE new_node . next = None NEW_LINE return new_node NEW_LINE DEDENT def find_head ( random ) : NEW_LINE INDENT if ( random == None ) : NEW_LINE INDENT return None NEW_LINE DEDENT head = None NEW_LINE var = random NEW_LINE while ( not ( var . data > var . next . data or var . next == random ) ) : NEW_LINE INDENT var = var . next NEW_LINE DEDENT return var . next NEW_LINE DEDENT def sortedInsert ( head_ref , new_node ) : NEW_LINE INDENT current = head_ref NEW_LINE if ( current == None ) : NEW_LINE INDENT new_node . next = new_node NEW_LINE head_ref = new_node NEW_LINE DEDENT elif ( current . data >= new_node . data ) : NEW_LINE INDENT while ( current . next != head_ref ) : NEW_LINE INDENT current = current . next NEW_LINE DEDENT current . next = new_node NEW_LINE new_node . next = head_ref NEW_LINE head_ref = new_node NEW_LINE DEDENT else : NEW_LINE INDENT while ( current . next != head_ref and current . next . data < new_node . data ) : NEW_LINE INDENT current = current . next NEW_LINE DEDENT new_node . next = current . next NEW_LINE current . next = new_node NEW_LINE DEDENT return head_ref NEW_LINE DEDENT def printList ( start ) : NEW_LINE INDENT temp = 0 NEW_LINE if ( start != None ) : NEW_LINE INDENT temp = start NEW_LINE while True : NEW_LINE INDENT print ( temp . data , end = ' ▁ ' ) NEW_LINE temp = temp . next NEW_LINE if ( temp == start ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 12 , 56 , 2 , 11 , 1 , 90 ] NEW_LINE start = None ; NEW_LINE temp = 0 NEW_LINE for i in range ( 6 ) : NEW_LINE INDENT if ( start != None ) : NEW_LINE INDENT for j in range ( randint ( 0 , 10 ) ) : NEW_LINE INDENT start = start . next NEW_LINE DEDENT DEDENT temp = create ( ) NEW_LINE temp . data = arr [ i ] NEW_LINE start = sortedInsert ( find_head ( start ) , temp ) NEW_LINE DEDENT printList ( find_head ( start ) ) NEW_LINE DEDENT
Convert a given Binary Tree to Circular Doubly Linked List | Set 2 | A binary tree node has data , and left and right pointers ; Function to perform In - Order traversal of the tree and store the nodes in a vector ; first recur on left child ; append the data of node in vector ; now recur on right child ; Function to convert Binary Tree to Circular Doubly Linked list using the vector which stores In - Order traversal of the Binary Tree ; Base cases ; Vector to be used for storing the nodes of tree in In - order form ; Calling the In - Order traversal function ; Create the head of the linked list pointing to the root of the tree ; Create a current pointer to be used in traversal ; Traversing the nodes of the tree starting from the second elements ; Create a temporary pointer pointing to current ; Current 's right points to the current  node in traversal ; Current points to its right ; Current 's left points to temp ; Current 's right points to head of the list ; Head 's left points to current ; Return head of the list ; Display Circular Link List ; Driver Code
class Node : NEW_LINE INDENT def __init__ ( self , data ) : NEW_LINE INDENT self . data = data NEW_LINE self . left = self . right = None NEW_LINE DEDENT DEDENT v = [ ] NEW_LINE def inorder ( root ) : NEW_LINE INDENT global v NEW_LINE if ( root == None ) : NEW_LINE INDENT return NEW_LINE DEDENT inorder ( root . left ) NEW_LINE v . append ( root . data ) NEW_LINE inorder ( root . right ) NEW_LINE DEDENT def bTreeToCList ( root ) : NEW_LINE INDENT global v NEW_LINE if ( root == None ) : NEW_LINE INDENT return None NEW_LINE DEDENT v = [ ] NEW_LINE inorder ( root ) NEW_LINE head_ref = Node ( v [ 0 ] ) NEW_LINE curr = head_ref NEW_LINE i = 1 NEW_LINE while ( i < len ( v ) ) : NEW_LINE INDENT temp = curr NEW_LINE curr . right = Node ( v [ i ] ) NEW_LINE curr = curr . right NEW_LINE curr . left = temp NEW_LINE i = i + 1 NEW_LINE DEDENT curr . right = head_ref NEW_LINE head_ref . left = curr NEW_LINE return head_ref NEW_LINE DEDENT def displayCList ( head ) : NEW_LINE INDENT print ( " Circular ▁ Doubly ▁ Linked ▁ List ▁ is ▁ : " , end = " " ) NEW_LINE itr = head NEW_LINE while ( True ) : NEW_LINE INDENT print ( itr . data , end = " ▁ " ) NEW_LINE itr = itr . right NEW_LINE if ( head == itr ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT print ( ) NEW_LINE DEDENT root = Node ( 10 ) NEW_LINE root . left = Node ( 12 ) NEW_LINE root . right = Node ( 15 ) NEW_LINE root . left . left = Node ( 25 ) NEW_LINE root . left . right = Node ( 30 ) NEW_LINE root . right . left = Node ( 36 ) NEW_LINE head = bTreeToCList ( root ) NEW_LINE displayCList ( head ) NEW_LINE
Deletion at different positions in a Circular Linked List | Function to delete last node of Circular Linked List ; check if list doesn 't have any node  if not then return ; check if list have single node if yes then delete it and return ; move first node to last previous
def DeleteLast ( head ) : NEW_LINE INDENT current = head NEW_LINE temp = head NEW_LINE previous = None NEW_LINE if ( head == None ) : NEW_LINE INDENT print ( " List is empty " ) NEW_LINE return None NEW_LINE DEDENT if ( current . next == current ) : NEW_LINE INDENT head = None NEW_LINE return None NEW_LINE DEDENT while ( current . next != head ) : NEW_LINE INDENT previous = current NEW_LINE current = current . next NEW_LINE DEDENT previous . next = current . next NEW_LINE head = previous . next NEW_LINE return head NEW_LINE DEDENT
Find minimum and maximum elements in singly Circular Linked List | structure for a node ; Function to print minimum and maximum nodes of the circular linked list ; check list is empty ; initialize head to current pointer ; initialize max int value to min initialize min int value to max ; While last node is not reached ; If current node data is lesser for min then replace it ; If current node data is greater for max then replace it ; Function to insert a node at the end of a Circular linked list ; Create a new node ; check node is created or not ; insert data into newly created node ; check list is empty if not have any node then make first node it ; if list have already some node ; move firt node to last node ; put first or head node address in new node link ; put new node address into last node link ( next ) ; Function to print the Circular linked list ; if list is empty simply show message ; traverse first to last node ; Driver Code
class Node : NEW_LINE INDENT def __init__ ( self ) : NEW_LINE INDENT self . data = 0 NEW_LINE self . next = None NEW_LINE DEDENT DEDENT def printMinMax ( head ) : NEW_LINE INDENT if ( head == None ) : NEW_LINE INDENT return ; NEW_LINE DEDENT current = head ; NEW_LINE min = 1000000000 NEW_LINE max = - 1000000000 ; NEW_LINE while True : NEW_LINE INDENT if ( current . data < min ) : NEW_LINE INDENT min = current . data ; NEW_LINE DEDENT if ( current . data > max ) : NEW_LINE INDENT max = current . data ; NEW_LINE DEDENT current = current . next ; NEW_LINE if ( current == head ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT print ( ' Minimum ▁ = ▁ { } , ▁ Maximum ▁ = ▁ { } ' . format ( min , max ) ) NEW_LINE DEDENT def insertNode ( head , data ) : NEW_LINE INDENT current = head ; NEW_LINE newNode = Node ( ) NEW_LINE if not newNode : NEW_LINE INDENT print ( " Memory Error " ) ; NEW_LINE return head NEW_LINE DEDENT newNode . data = data ; NEW_LINE if ( head == None ) : NEW_LINE INDENT newNode . next = newNode ; NEW_LINE head = newNode ; NEW_LINE return head NEW_LINE DEDENT else : NEW_LINE INDENT while ( current . next != head ) : NEW_LINE INDENT current = current . next ; NEW_LINE DEDENT newNode . next = head ; NEW_LINE current . next = newNode ; NEW_LINE DEDENT return head NEW_LINE DEDENT def displayList ( head ) : NEW_LINE INDENT current = head ; NEW_LINE if ( head == None ) : NEW_LINE INDENT print ( " Display List is empty " ) ; NEW_LINE return ; NEW_LINE DEDENT else : NEW_LINE INDENT while True : NEW_LINE INDENT print ( current . data , end = ' ▁ ' ) ; NEW_LINE current = current . next ; NEW_LINE if ( current == head ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT DEDENT print ( ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT Head = None ; NEW_LINE Head = insertNode ( Head , 99 ) ; NEW_LINE Head = insertNode ( Head , 11 ) ; NEW_LINE Head = insertNode ( Head , 22 ) ; NEW_LINE Head = insertNode ( Head , 33 ) ; NEW_LINE Head = insertNode ( Head , 44 ) ; NEW_LINE Head = insertNode ( Head , 55 ) ; NEW_LINE Head = insertNode ( Head , 66 ) ; NEW_LINE print ( " Initial ▁ List : ▁ " , end = ' ' ) NEW_LINE displayList ( Head ) ; NEW_LINE printMinMax ( Head ) ; NEW_LINE DEDENT