dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
class newNode :
    def __init__ ( self , key ) :
        self . key = key
        self . left = None
        self . right = None
def printList ( head ) :
    while ( head != None ) :
        print ( head . key , end = " ▁ " )
        head = head . next
    print ( )
def detectLoop ( head ) :
    temp = " "
    while ( head != None ) :
        if ( head . next == None ) :
            return False
        if ( head . next == temp ) :
            return True
        nex = head . next
        head . next = temp
        head = nex
    return False
head = newNode ( 1 )
head . next = newNode ( 2 )
head . next . next = newNode ( 3 )
head . next . next . next = newNode ( 4 )
head . next . next . next . next = newNode ( 5 )
head . next . next . next . next . next = head . next . next
found = detectLoop ( head )
if ( found ) :
    print ( " Loop ▁ Found " )
else :
    print ( " No ▁ Loop " )

Class/struct names: newNode
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . next = None
class LinkedList :
    def __init__ ( self ) :
        self . head = None
    def isPalindrome ( self , head ) :
        slow_ptr = head
        fast_ptr = head
        prev_of_slow_ptr = head
        midnode = None
        res = True
        if ( head != None and head . next != None ) :
            while ( fast_ptr != None and fast_ptr . next != None ) :
                fast_ptr = fast_ptr . next . next
                prev_of_slow_ptr = slow_ptr
                slow_ptr = slow_ptr . next
            if ( fast_ptr != None ) :
                midnode = slow_ptr
                slow_ptr = slow_ptr . next
            second_half = slow_ptr
            prev_of_slow_ptr . next = None
            second_half = self . reverse ( second_half )
            res = self . compareLists ( head , second_half )
            second_half = self . reverse ( second_half )
            if ( midnode != None ) :
                prev_of_slow_ptr . next = midnode
                midnode . next = second_half
            else :
                prev_of_slow_ptr . next = second_half
        return res
    def reverse ( self , second_half ) :
        prev = None
        current = second_half
        next = None
        while current != None :
            next = current . next
            current . next = prev
            prev = current
            current = next
        second_half = prev
        return second_half
    def compareLists ( self , head1 , head2 ) :
        temp1 = head1
        temp2 = head2
        while ( temp1 and temp2 ) :
            if ( temp1 . data == temp2 . data ) :
                temp1 = temp1 . next
                temp2 = temp2 . next
            else :
                return 0
        if ( temp1 == None and temp2 == None ) :
            return 1
        return 0
    def push ( self , new_data ) :
        new_node = Node ( new_data )
        new_node . next = self . head
        self . head = new_node
    def printList ( self ) :
        temp = self . head
        while ( temp ) :
            print ( temp . data , end = " - > " )
            temp = temp . next
        print ( " NULL " )
if __name__ == ' _ _ main _ _ ' :
    l = LinkedList ( )
    s = [ ' a ' , ' b ' , ' a ' , ' c ' , ' a ' , ' b ' , ' a ' ]
    for i in range ( 7 ) :
        l . push ( s [ i ] )
        l . printList ( )
        if ( l . isPalindrome ( l . head ) != False ) :
            print ( " Is Palindrome " )
        else :
            print ( " Not Palindrome " )
        print ( )

Index/key variables: i
Iterator variables: i
Boolean variables: res
Class/struct names: LinkedList, Node
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def postorder ( head ) :
    temp = head
    visited = set ( )
    while ( temp and temp not in visited ) :
        if ( temp . left and temp . left not in visited ) :
            temp = temp . left
        elif ( temp . right and temp . right not in visited ) :
            temp = temp . right
        else :
            print ( temp . data , end = " ▁ " )
            visited . add ( temp )
            temp = head
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 8 )
    root . left = newNode ( 3 )
    root . right = newNode ( 10 )
    root . left . left = newNode ( 1 )
    root . left . right = newNode ( 6 )
    root . left . right . left = newNode ( 4 )
    root . left . right . right = newNode ( 7 )
    root . right . right = newNode ( 14 )
    root . right . right . left = newNode ( 13 )
    postorder ( root )

Accumulator variables: visited
Class/struct names: newNode
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
        self . visited = False
def postorder ( head ) :
    temp = head
    while ( temp and temp . visited == False ) :
        if ( temp . left and temp . left . visited == False ) :
            temp = temp . left
        elif ( temp . right and temp . right . visited == False ) :
            temp = temp . right
        else :
            print ( temp . data , end = " ▁ " )
            temp . visited = True
            temp = head
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 8 )
    root . left = newNode ( 3 )
    root . right = newNode ( 10 )
    root . left . left = newNode ( 1 )
    root . left . right = newNode ( 6 )
    root . left . right . left = newNode ( 4 )
    root . left . right . right = newNode ( 7 )
    root . right . right = newNode ( 14 )
    root . right . right . left = newNode ( 13 )
    postorder ( root )

Class/struct names: newNode
Python program:
class Node :
    def __init__ ( self , x ) :
        self . data = x
        self . next = None
def getJosephusPosition ( m , n ) :
    head = Node ( 1 )
    prev = head
    for i in range ( 2 , n + 1 ) :
        prev . next = Node ( i )
        prev = prev . next
        prev . next = head
    ptr1 = head
    ptr2 = head
    while ( ptr1 . next != ptr1 ) :
        count = 1
        while ( count != m ) :
            ptr2 = ptr1
            ptr1 = ptr1 . next
            count += 1
        ptr2 . next = ptr1 . next
        ptr1 = ptr2 . next
    print ( " Last ▁ person ▁ left ▁ standing ▁ ( Josephus ▁ Position ) ▁ is ▁ " , ptr1 . data )
if __name__ == ' _ _ main _ _ ' :
    n = 14
    m = 2
    getJosephusPosition ( m , n )

Accumulator variables: count
Iterator variables: i
Class/struct names: Node
Python program:
tree = [ None ] * 10
def root ( key ) :
    if tree [ 0 ] != None :
        print ( " Tree ▁ already ▁ had ▁ root " )
    else :
        tree [ 0 ] = key
def set_left ( key , parent ) :
    if tree [ parent ] == None :
        print ( " Can ' t ▁ set ▁ child ▁ at " , ( parent * 2 ) + 1 , " , ▁ no ▁ parent ▁ found " )
    else :
        tree [ ( parent * 2 ) + 1 ] = key
def set_right ( key , parent ) :
    if tree [ parent ] == None :
        print ( " Can ' t ▁ set ▁ child ▁ at " , ( parent * 2 ) + 2 , " , ▁ no ▁ parent ▁ found " )
    else :
        tree [ ( parent * 2 ) + 2 ] = key
def print_tree ( ) :
    for i in range ( 10 ) :
        if tree [ i ] != None :
            print ( tree [ i ] , end = " " )
        else :
            print ( " - " , end = " " )
    print ( )
root ( ' A ' )
set_right ( ' C ' , 0 )
set_left ( ' D ' , 1 )
set_right ( ' E ' , 1 )
set_right ( ' F ' , 2 )
print_tree ( )

Index/key variables: i, parent
Iterator variables: i
Python program:
class Node :
    def __init__ ( self , data , next = None ) :
        self . data = data
        self . next = next
class LinkedList :
    def __init__ ( self , * args , ** kwargs ) :
        self . head = Node ( None )
    def push ( self , data ) :
        node = Node ( data )
        node . next = self . head
        self . head = node
    def printList ( self ) :
        node = self . head
        while node . next is not None :
            print ( node . data , end = " ▁ " )
            node = node . next
    def countNodes ( self ) :
        count = 0
        node = self . head
        while node . next is not None :
            count += 1
            node = node . next
        return count
    def swapKth ( self , k ) :
        n = self . countNodes ( )
        if n < k :
            return
        if ( 2 * k - 1 ) == n :
            return
        x = self . head
        x_prev = Node ( None )
        for i in range ( k - 1 ) :
            x_prev = x
            x = x . next
        y = self . head
        y_prev = Node ( None )
        for i in range ( n - k ) :
            y_prev = y
            y = y . next
        if x_prev is not None :
            x_prev . next = y
        if y_prev is not None :
            y_prev . next = x
        temp = x . next
        x . next = y . next
        y . next = temp
        if k == 1 :
            self . head = y
        if k == n :
            self . head = x
llist = LinkedList ( )
for i in range ( 8 , 0 , - 1 ) :
    llist . push ( i )
llist . printList ( )
for i in range ( 1 , 9 ) :
    llist . swapKth ( i )
    print ( " Modified ▁ List ▁ for ▁ k ▁ = ▁ " , i )
    llist . printList ( )
    print ( " " )

Accumulator variables: count
Iterator variables: i
Class/struct names: LinkedList, Node
Python program:
class Node :
    def __init__ ( self , x ) :
        self . data = x
        self . next = None
        self . prev = None
def pairSum ( head , x ) :
    first = head
    second = head
    while ( second . next != None ) :
        second = second . next
    found = False
    while ( first != second and second . next != first ) :
        if ( ( first . data + second . data ) == x ) :
            found = True
            print ( " ( " , first . data , " , " , second . data , " ) " )
            first = first . next
            second = second . prev
        else :
            if ( ( first . data + second . data ) < x ) :
                first = first . next
            else :
                second = second . prev
    if ( found == False ) :
        print ( " No ▁ pair ▁ found " )
def insert ( head , data ) :
    temp = Node ( data )
    if not head :
        head = temp
    else :
        temp . next = head
        head . prev = temp
        head = temp
    return head
if __name__ == ' _ _ main _ _ ' :
    head = None
    head = insert ( head , 9 )
    head = insert ( head , 8 )
    head = insert ( head , 6 )
    head = insert ( head , 5 )
    head = insert ( head , 4 )
    head = insert ( head , 2 )
    head = insert ( head , 1 )
    x = 7
    pairSum ( head , x )

Boolean variables: found
Class/struct names: Node
Python program:
class Node :
    def __init__ ( self , data ) :
        self . val = data
        self . left = None
        self . right = None
def diagonalprint ( root ) :
    if root is None :
        return
    q = [ ]
    q . append ( root )
    q . append ( None )
    while len ( q ) > 0 :
        temp = q . pop ( 0 )
        if not temp :
            if len ( q ) == 0 :
                return
            print ( ' ▁ ' )
            q . append ( None )
        else :
            while temp :
                print ( temp . val , end = ' ▁ ' )
                if temp . left :
                    q . append ( temp . left )
                temp = temp . right
root = Node ( 8 )
root . left = Node ( 3 )
root . right = Node ( 10 )
root . left . left = Node ( 1 )
root . left . right = Node ( 6 )
root . right . right = Node ( 14 )
root . right . right . left = Node ( 13 )
root . left . right . left = Node ( 4 )
root . left . right . right = Node ( 7 )
diagonalprint ( root )

Accumulator variables: q
Class/struct names: Node
Python program:
class Node :
    def __init__ ( self , x ) :
        self . data = x
        self . next = None
        self . prev = None
def countPairs ( first , second , value ) :
    count = 0
    while ( first != None and second != None and first != second and second . next != first ) :
        if ( ( first . data + second . data ) == value ) :
            count += 1
            first = first . next
            second = second . prev
        elif ( ( first . data + second . data ) > value ) :
            second = second . prev
        else :
            first = first . next
    return count
def countTriplets ( head , x ) :
    if ( head == None ) :
        return 0
    current , first , last = head , None , None
    count = 0
    last = head
    while ( last . next != None ) :
        last = last . next
    while current != None :
        first = current . next
        count , current = count + countPairs ( first , last , x - current . data ) , current . next
    return count
def insert ( head , data ) :
    temp = Node ( data )
    if ( head == None ) :
        head = temp
    else :
        temp . next = head
        head . prev = temp
        head = temp
    return head
if __name__ == ' _ _ main _ _ ' :
    head = None
    head = insert ( head , 9 )
    head = insert ( head , 8 )
    head = insert ( head , 6 )
    head = insert ( head , 5 )
    head = insert ( head , 4 )
    head = insert ( head , 2 )
    head = insert ( head , 1 )
    x = 17
    print ( " Count ▁ = ▁ " , countTriplets ( head , x ) )

Accumulator variables: count
Class/struct names: Node
Python program:
class Node :
    def __init__ ( self , data = None , next = None ) :
        self . next = next
        self . data = data
def deleteNode ( head_ref , del_ ) :
    if ( head_ref == None or del_ == None ) :
        return head_ref
    if ( head_ref == del_ ) :
        head_ref = del_ . next
    if ( del_ . next != None ) :
        del_ . next . prev = del_ . prev
    if ( del_ . prev != None ) :
        del_ . prev . next = del_ . next
    return head_ref
def removeDuplicates ( head_ref ) :
    if ( ( head_ref ) == None or ( head_ref ) . next == None ) :
        return head_ref
    ptr1 = head_ref
    ptr2 = None
    while ( ptr1 != None ) :
        ptr2 = ptr1 . next
        while ( ptr2 != None ) :
            if ( ptr1 . data == ptr2 . data ) :
                next = ptr2 . next
                head_ref = deleteNode ( head_ref , ptr2 )
                ptr2 = next
            else :
                ptr2 = ptr2 . next
        ptr1 = ptr1 . next
    return head_ref
def push ( head_ref , new_data ) :
    new_node = Node ( )
    new_node . data = new_data
    new_node . prev = None
    new_node . next = ( head_ref )
    if ( ( head_ref ) != None ) :
        ( head_ref ) . prev = new_node
    ( head_ref ) = new_node
    return head_ref
def printList ( head ) :
    if ( head == None ) :
        print ( " Doubly ▁ Linked ▁ list ▁ empty " )
    while ( head != None ) :
        print ( head . data , end = " ▁ " )
        head = head . next
head = None
head = push ( head , 12 )
head = push ( head , 12 )
head = push ( head , 10 )
head = push ( head , 4 )
head = push ( head , 8 )
head = push ( head , 4 )
head = push ( head , 6 )
head = push ( head , 4 )
head = push ( head , 4 )
head = push ( head , 8 )
print ( " Original ▁ Doubly ▁ linked ▁ list : " )
printList ( head )
head = removeDuplicates ( head )
print ( " Doubly linked list after removing duplicates : " )
printList ( head )

Class/struct names: Node
Python program:
class Node :
    def __init__ ( self ) :
        self . data = 0
        self . next = None
        self . prev = None
def deleteNode ( head_ref , del_ ) :
    if ( head_ref == None or del_ == None ) :
        return None
    if ( head_ref == del_ ) :
        head_ref = del_ . next
    if ( del_ . next != None ) :
        del_ . next . prev = del_ . prev
    if ( del_ . prev != None ) :
        del_ . prev . next = del_ . next
    return head_ref
def removeDuplicates ( head_ref ) :
    if ( ( head_ref ) == None ) :
        return None
    us = set ( )
    current = head_ref
    next = None
    while ( current != None ) :
        if ( ( current . data ) in us ) :
            next = current . next
            head_ref = deleteNode ( head_ref , current )
            current = next
        else :
            us . add ( current . data )
            current = current . next
    return head_ref
def push ( head_ref , new_data ) :
    new_node = Node ( )
    new_node . data = new_data
    new_node . prev = None
    new_node . next = ( head_ref )
    if ( ( head_ref ) != None ) :
        ( head_ref ) . prev = new_node
    ( head_ref ) = new_node
    return head_ref
def printList ( head ) :
    if ( head == None ) :
        print ( " Doubly ▁ Linked ▁ list ▁ empty " )
    while ( head != None ) :
        print ( head . data , end = " ▁ " )
        head = head . next
head = None
head = push ( head , 12 )
head = push ( head , 12 )
head = push ( head , 10 )
head = push ( head , 4 )
head = push ( head , 8 )
head = push ( head , 4 )
head = push ( head , 6 )
head = push ( head , 4 )
head = push ( head , 4 )
head = push ( head , 8 )
print ( " Original ▁ Doubly ▁ linked ▁ list : " )
printList ( head )
head = removeDuplicates ( head )
print ( " Doubly linked list after removing duplicates : " )
printList ( head )

Accumulator variables: us
Class/struct names: Node
Python program:
class Node :
    def __init__ ( self , data ) :
        self . info = data
        self . next = None
        self . prev = None
head = None
tail = None
def nodeInsetail ( key ) :
    global head
    global tail
    p = Node ( 0 )
    p . info = key
    p . next = None
    if ( ( head ) == None ) :
        ( head ) = p
        ( tail ) = p
        ( head ) . prev = None
        return
    if ( ( p . info ) < ( ( head ) . info ) ) :
        p . prev = None
        ( head ) . prev = p
        p . next = ( head )
        ( head ) = p
        return
    if ( ( p . info ) > ( ( tail ) . info ) ) :
        p . prev = ( tail )
        ( tail ) . next = p
        ( tail ) = p
        return
    temp = ( head ) . next
    while ( ( temp . info ) < ( p . info ) ) :
        temp = temp . next
    ( temp . prev ) . next = p
    p . prev = temp . prev
    temp . prev = p
    p . next = temp
def printList ( temp ) :
    while ( temp != None ) :
        print ( temp . info , end = " ▁ " )
        temp = temp . next
nodeInsetail ( 30 )
nodeInsetail ( 50 )
nodeInsetail ( 90 )
nodeInsetail ( 10 )
nodeInsetail ( 40 )
nodeInsetail ( 110 )
nodeInsetail ( 60 )
nodeInsetail ( 95 )
nodeInsetail ( 23 )
print ( " Doubly linked list on printing from left to right " )
printList ( head )

Class/struct names: Node
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . next = None
        self . prev = None
def insertEnd ( value ) :
    global start
    if ( start == None ) :
        new_node = Node ( 0 )
        new_node . data = value
        new_node . next = new_node . prev = new_node
        start = new_node
        return
    last = ( start ) . prev
    new_node = Node ( 0 )
    new_node . data = value
    new_node . next = start
    ( start ) . prev = new_node
    new_node . prev = last
    last . next = new_node
def insertBegin ( value ) :
    global start
    last = ( start ) . prev
    new_node = Node ( 0 )
    new_node . data = value
    new_node . next = start
    new_node . prev = last
    last . next = ( start ) . prev = new_node
    start = new_node
def insertAfter ( value1 , value2 ) :
    global start
    new_node = Node ( 0 )
    new_node . data = value1
    temp = start
    while ( temp . data != value2 ) :
        temp = temp . next
    next = temp . next
    temp . next = new_node
    new_node . prev = temp
    new_node . next = next
    next . prev = new_node
def display ( ) :
    global start
    temp = start
    print ( " Traversal ▁ in ▁ forward ▁ direction : " )
    while ( temp . next != start ) :
        print ( temp . data , end = " ▁ " )
        temp = temp . next
    print ( temp . data )
    print ( " Traversal ▁ in ▁ reverse ▁ direction : " )
    last = start . prev
    temp = last
    while ( temp . prev != last ) :
        print ( temp . data , end = " ▁ " )
        temp = temp . prev
    print ( temp . data )
if __name__ == ' _ _ main _ _ ' :
    global start
    start = None
    insertEnd ( 5 )
    insertBegin ( 4 )
    insertEnd ( 7 )
    insertEnd ( 8 )
    insertAfter ( 6 , 5 )
    print ( " Created ▁ circular ▁ doubly ▁ linked ▁ list ▁ is : ▁ " )
    display ( )

Class/struct names: Node
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def printLeaves ( root ) :
    if ( root ) :
        printLeaves ( root . left )
        if root . left is None and root . right is None :
            print ( root . data ) ,
        printLeaves ( root . right )
def printBoundaryLeft ( root ) :
    if ( root ) :
        if ( root . left ) :
            print ( root . data )
            printBoundaryLeft ( root . left )
        elif ( root . right ) :
            print ( root . data )
            printBoundaryLeft ( root . right )
def printBoundaryRight ( root ) :
    if ( root ) :
        if ( root . right ) :
            printBoundaryRight ( root . right )
            print ( root . data )
        elif ( root . left ) :
            printBoundaryRight ( root . left )
            print ( root . data )
def printBoundary ( root ) :
    if ( root ) :
        print ( root . data )
        printBoundaryLeft ( root . left )
        printLeaves ( root . left )
        printLeaves ( root . right )
        printBoundaryRight ( root . right )
root = Node ( 20 )
root . left = Node ( 8 )
root . left . left = Node ( 4 )
root . left . right = Node ( 12 )
root . left . right . left = Node ( 10 )
root . left . right . right = Node ( 14 )
root . right = Node ( 22 )
root . right . right = Node ( 25 )
printBoundary ( root )

Class/struct names: Node
Python program:
class Node :
    def __init__ ( self ) :
        self . data = 0
        self . next = None
def printReverse ( head_ref , n ) :
    j = 0
    current = head_ref
    while ( current != None ) :
        i = 0
        while ( i < 2 * ( n - j ) ) :
            print ( end = " ▁ " )
            i = i + 1
        print ( current . data , end = " " )
        current = current . next
        j = j + 1
def push ( head_ref , new_data ) :
    new_node = Node ( )
    new_node . data = new_data
    new_node . next = ( head_ref )
    ( head_ref ) = new_node
    return head_ref ;
def printList ( head ) :
    i = 0
    temp = head
    while ( temp != None ) :
        print ( temp . data , end = " ▁ " )
        temp = temp . next
        i = i + 1
    return i
head = None
head = push ( head , 1 )
head = push ( head , 2 )
head = push ( head , 3 )
head = push ( head , 4 )
head = push ( head , 5 )
head = push ( head , 6 )
print ( " Given ▁ linked ▁ list : " )
n = printList ( head )
print ( " Reversed Linked list : " )
printReverse ( head , n )
print ( )

Class/struct names: Node
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . next = None

Class/struct names: Node
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . next = None
def fun1 ( head ) :
    if ( head == None ) :
        return
    fun1 ( head . next )
    print ( head . data , end = " ▁ " )
def fun2 ( start ) :
    if ( start == None ) :
        return
    print ( start . data , end = " ▁ " )
    if ( start . next != None ) :
        fun2 ( start . next . next )
    print ( start . data , end = " ▁ " )
def push ( head , new_data ) :
    new_node = Node ( new_data )
    new_node . next = head
    head = new_node
    return head
head = None
head = Node ( 5 )
head = push ( head , 4 )
head = push ( head , 3 )
head = push ( head , 2 )
head = push ( head , 1 )
print ( " Output ▁ of ▁ fun1 ( ) ▁ for ▁ list ▁ 1 - > 2 - > 3 - > 4 - > 5" )
fun1 ( head )
print ( " Output of fun2 ( ) for list 1 -> 2 -> 3 -> 4 -> 5 " )
fun2 ( head )

Class/struct names: Node