dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def isOperand ( x ) :
    return ( ( x >= ' a ' and x <= ' z ' ) or ( x >= ' A ' and x <= ' Z ' ) )
def getInfix ( exp ) :
    s = [ ]
    for i in exp :
        if ( isOperand ( i ) ) :
            s . insert ( 0 , i )
        else :
            op1 = s [ 0 ]
            s . pop ( 0 )
            op2 = s [ 0 ]
            s . pop ( 0 )
            s . insert ( 0 , " ( " + op2 + i + op1 + " ) " )
    return s [ 0 ]
if __name__ == ' _ _ main _ _ ' :
    exp = " ab * c + "
    print ( getInfix ( exp . strip ( ) ) )

Iterator variables: i
Python program:
class newNode :
    def __init__ ( self , key ) :
        self . data = key
        self . left = None
        self . right = None
def updatetree ( root ) :
    if ( not root ) :
        return 0
    if ( root . left == None and root . right == None ) :
        return root . data
    leftsum = updatetree ( root . left )
    rightsum = updatetree ( root . right )
    root . data += leftsum
    return root . data + rightsum
def inorder ( node ) :
    if ( node == None ) :
        return
    inorder ( node . left )
    print ( node . data , end = " ▁ " )
    inorder ( node . right )
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 1 )
    root . left = newNode ( 2 )
    root . right = newNode ( 3 )
    root . left . left = newNode ( 4 )
    root . left . right = newNode ( 5 )
    root . right . right = newNode ( 6 )
    updatetree ( root )
    print ( " Inorder ▁ traversal ▁ of ▁ the ▁ modified ▁ tree ▁ is " )
    inorder ( root )

Class/struct names: newNode
Python program:
def calculateSpan ( price , n , S ) :
    S [ 0 ] = 1
    for i in range ( 1 , n , 1 ) :
        S [ i ] = 1
        j = i - 1
        while ( j >= 0 ) and ( price [ i ] >= price [ j ] ) :
            S [ i ] += 1
            j -= 1
def printArray ( arr , n ) :
    for i in range ( n ) :
        print ( arr [ i ] , end = " ▁ " )
price = [ 10 , 4 , 5 , 90 , 120 , 80 ]
n = len ( price )
S = [ None ] * n
calculateSpan ( price , n , S )
printArray ( S , n )

Index/key variables: i, j
Iterator variables: i
Python program:
def calculateSpan ( price , S ) :
    n = len ( price )
    st = [ ]
    st . append ( 0 )
    S [ 0 ] = 1
    for i in range ( 1 , n ) :
        while ( len ( st ) > 0 and price [ st [ - 1 ] ] <= price [ i ] ) :
            st . pop ( )
        S [ i ] = i + 1 if len ( st ) <= 0 else ( i - st [ - 1 ] )
        st . append ( i )
def printArray ( arr , n ) :
    for i in range ( 0 , n ) :
        print ( arr [ i ] , end = " ▁ " )
price = [ 10 , 4 , 5 , 90 , 120 , 80 ]
S = [ 0 for i in range ( len ( price ) + 1 ) ]
calculateSpan ( price , S )
printArray ( S , len ( price ) )

Index/key variables: i
Accumulator variables: st
Iterator variables: i
Python program:
def calculateSpan ( A , n , ans ) :
    ans [ 0 ] = 1
    for i in range ( 1 , n ) :
        counter = 1
        while ( ( i - counter ) >= 0 and A [ i ] >= A [ i - counter ] ) :
            counter += ans [ i - counter ]
        ans [ i ] = counter
def printArray ( arr , n ) :
    for i in range ( n ) :
        print ( arr [ i ] , end = ' ▁ ' )
    print ( )
price = [ 10 , 4 , 5 , 90 , 120 , 80 ]
n = len ( price )
S = [ 0 ] * ( n )
calculateSpan ( price , n , S )
printArray ( S , n )

Index/key variables: i
Accumulator variables: counter
Iterator variables: i
Python program:
def printNGE ( arr ) :
    for i in range ( 0 , len ( arr ) , 1 ) :
        next = - 1
        for j in range ( i + 1 , len ( arr ) , 1 ) :
            if arr [ i ] < arr [ j ] :
                next = arr [ j ]
                break
        print ( str ( arr [ i ] ) + " ▁ - - ▁ " + str ( next ) )
arr = [ 11 , 13 , 21 , 3 ]
printNGE ( arr )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def nextGreaterInLeft ( a ) :
    left_index = [ 0 ] * len ( a )
    s = [ ]
    for i in range ( len ( a ) ) :
        while len ( s ) != 0 and a [ i ] >= a [ s [ - 1 ] ] :
            s . pop ( )
        if len ( s ) != 0 :
            left_index [ i ] = s [ - 1 ]
        else :
            left_index [ i ] = 0
        s . append ( i )
    return left_index
def nextGreaterInRight ( a ) :
    right_index = [ 0 ] * len ( a )
    s = [ ]
    for i in range ( len ( a ) - 1 , - 1 , - 1 ) :
        while len ( s ) != 0 and a [ i ] >= a [ s [ - 1 ] ] :
            s . pop ( )
        if len ( s ) != 0 :
            right_index [ i ] = s [ - 1 ]
        else :
            right_index [ i ] = 0
        s . append ( i )
    return right_index
def LRProduct ( arr ) :
    left = nextGreaterInLeft ( arr )
    right = nextGreaterInRight ( arr )
    ans = - 1
    for i in range ( 1 , len ( left ) - 1 ) :
        if left [ i ] == 0 or right [ i ] == 0 :
            ans = max ( ans , 0 )
        else :
            temp = ( left [ i ] + 1 ) * ( right [ i ] + 1 )
            ans = max ( ans , temp )
    return ans
arr = [ 5 , 4 , 3 , 4 , 5 ]
print ( LRProduct ( arr ) )

Index/key variables: i
Accumulator variables: s
Iterator variables: i
Python program:
N = 8
MATRIX = [ [ 0 , 0 , 1 , 0 ] , [ 0 , 0 , 1 , 0 ] , [ 0 , 0 , 0 , 0 ] , [ 0 , 0 , 1 , 0 ] ]
def knows ( a , b ) :
    return MATRIX [ a ] [ b ]
def findCelebrity ( n ) :
    indegree = [ 0 for x in range ( n ) ]
    outdegree = [ 0 for x in range ( n ) ]
    for i in range ( n ) :
        for j in range ( n ) :
            x = knows ( i , j )
            outdegree [ i ] += x
            indegree [ j ] += x
    for i in range ( n ) :
        if ( indegree [ i ] == n - 1 and outdegree [ i ] == 0 ) :
            return i
    return - 1
if __name__ == ' _ _ main _ _ ' :
    n = 4
    id_ = findCelebrity ( n )
    if id_ == - 1 :
        print ( " No ▁ celebrity " )
    else :
        print ( " Celebrity ▁ ID " , id_ )

Index/key variables: a, b, i, j
Iterator variables: i, j
Python program:
N = 8
MATRIX = [ [ 0 , 0 , 1 , 0 ] , [ 0 , 0 , 1 , 0 ] , [ 0 , 0 , 0 , 0 ] , [ 0 , 0 , 1 , 0 ] ]
def knows ( a , b ) :
    return MATRIX [ a ] [ b ]
def findPotentialCelebrity ( n ) :
    if ( n == 0 ) :
        return 0 ;
    id_ = findPotentialCelebrity ( n - 1 )
    if ( id_ == - 1 ) :
        return n - 1
    elif knows ( id_ , n - 1 ) :
        return n - 1
    elif knows ( n - 1 , id_ ) :
        return id_
    return - 1
def Celebrity ( n ) :
    id_ = findPotentialCelebrity ( n )
    if ( id_ == - 1 ) :
        return id_
    else :
        c1 = 0
        c2 = 0
        for i in range ( n ) :
            if ( i != id_ ) :
                c1 += knows ( id_ , i )
                c2 += knows ( i , id_ )
        if ( c1 == 0 and c2 == n - 1 ) :
            return id_
        return - 1
if __name__ == ' _ _ main _ _ ' :
    n = 4
    id_ = Celebrity ( n )
    if id_ == - 1 :
        print ( " No ▁ celebrity " )
    else :
        print ( " Celebrity ▁ ID " , id_ )

Index/key variables: a, b
Accumulator variables: c1, c2
Iterator variables: i
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def mirror ( root ) :
    if ( root == None ) :
        return
    q = [ ]
    q . append ( root )
    while ( len ( q ) ) :
        curr = q [ 0 ]
        q . pop ( 0 )
        curr . left , curr . right = curr . right , curr . left
        if ( curr . left ) :
            q . append ( curr . left )
        if ( curr . right ) :
            q . append ( curr . right )
def inOrder ( node ) :
    if ( node == None ) :
        return
    inOrder ( node . left )
    print ( node . data , end = " ▁ " )
    inOrder ( node . right )
root = newNode ( 1 )
root . left = newNode ( 2 )
root . right = newNode ( 3 )
root . left . left = newNode ( 4 )
root . left . right = newNode ( 5 )
print ( " Inorder ▁ traversal ▁ of ▁ the ▁ constructed ▁ tree ▁ is " )
inOrder ( root )
mirror ( root )
print ( " Inorder traversal of the mirror tree is " )
inOrder ( root )

Accumulator variables: q
Class/struct names: newNode
Python program:
class Stack :
    def __init__ ( self ) :
        self . items = [ ]
    def isEmpty ( self ) :
        return self . items == [ ]
    def push ( self , item ) :
        self . items . append ( item )
    def pop ( self ) :
        return self . items . pop ( )
    def peek ( self ) :
        return self . items [ len ( self . items ) - 1 ]
    def size ( self ) :
        return len ( self . items )
def deleteMid ( st , n , curr ) :
    if ( st . isEmpty ( ) or curr == n ) :
        return
    x = st . peek ( )
    st . pop ( )
    deleteMid ( st , n , curr + 1 )
    if ( curr != int ( n / 2 ) ) :
        st . push ( x )
st = Stack ( )
st . push ( '1' )
st . push ( '2' )
st . push ( '3' )
st . push ( '4' )
st . push ( '5' )
st . push ( '6' )
st . push ( '7' )
deleteMid ( st , st . size ( ) , 0 )
while ( st . isEmpty ( ) == False ) :
    p = st . peek ( )
    st . pop ( )
    print ( str ( p ) + " ▁ " , end = " " )

Class/struct names: Stack
Python program:
def sortStack ( input ) :
    tmpStack = [ ]
    while ( len ( input ) > 0 ) :
        tmp = input [ - 1 ]
        input . pop ( )
        while ( len ( tmpStack ) > 0 and tmpStack [ - 1 ] < tmp ) :
            input . append ( tmpStack [ - 1 ] )
            tmpStack . pop ( )
        tmpStack . append ( tmp )
    return tmpStack
def sortArrayUsingStacks ( arr , n ) :
    input = [ ]
    i = 0
    while ( i < n ) :
        input . append ( arr [ i ] )
        i = i + 1
    tmpStack = sortStack ( input )
    i = 0
    while ( i < n ) :
        arr [ i ] = tmpStack [ - 1 ]
        tmpStack . pop ( )
        i = i + 1
    return arr
arr = [ 10 , 5 , 15 , 45 ]
n = len ( arr )
arr = sortArrayUsingStacks ( arr , n )
i = 0
while ( i < n ) :
    print ( arr [ i ] , end = " ▁ " )
    i = i + 1

Index/key variables: i
Accumulator variables: input, tmpStack
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def push ( head_ref , node ) :
    node . right = ( head_ref )
    node . left = None
    if ( ( head_ref ) != None ) :
        ( head_ref ) . left = node
    ( head_ref ) = node
def printList ( node ) :
    i = 0
    while ( i < len ( node ) ) :
        print ( node [ i ] . data , end = " ▁ " )
        i += 1
def spiralLevelOrder ( root ) :
    if ( root == None ) :
        return
    q = [ ]
    q . append ( root )
    stk = [ ]
    level = 0
    while ( len ( q ) ) :
        nodeCount = len ( q )
        if ( level & 1 ) :
            while ( nodeCount > 0 ) :
                node = q [ 0 ]
                q . pop ( 0 )
                stk . append ( node )
                if ( node . left != None ) :
                    q . append ( node . left )
                if ( node . right != None ) :
                    q . append ( node . right )
                nodeCount -= 1
        else :
            while ( nodeCount > 0 ) :
                node = q [ - 1 ]
                q . pop ( - 1 )
                stk . append ( node )
                if ( node . right != None ) :
                    q . insert ( 0 , node . right )
                if ( node . left != None ) :
                    q . insert ( 0 , node . left )
                nodeCount -= 1
        level += 1
    head = [ ]
    while ( len ( stk ) ) :
        head . append ( stk [ 0 ] )
        stk . pop ( 0 )
    print ( " Created ▁ DLL ▁ is : " )
    printList ( head )
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 1 )
    root . left = newNode ( 2 )
    root . right = newNode ( 3 )
    root . left . left = newNode ( 4 )
    root . left . right = newNode ( 5 )
    root . right . left = newNode ( 6 )
    root . right . right = newNode ( 7 )
    root . left . left . left = newNode ( 8 )
    root . left . left . right = newNode ( 9 )
    root . left . right . left = newNode ( 10 )
    root . left . right . right = newNode ( 11 )
    root . right . left . right = newNode ( 13 )
    root . right . right . left = newNode ( 14 )
    spiralLevelOrder ( root )

Index/key variables: i
Accumulator variables: head, level, nodeCount, q, stk
Class/struct names: newNode
Python program:
def reverserWords ( string ) :
    st = list ( )
    for i in range ( len ( string ) ) :
        if string [ i ] != " ▁ " :
            st . append ( string [ i ] )
        else :
            while len ( st ) > 0 :
                print ( st [ - 1 ] , end = " " )
                st . pop ( )
            print ( end = " ▁ " )
    while len ( st ) > 0 :
        print ( st [ - 1 ] , end = " " )
        st . pop ( )
if __name__ == " _ _ main _ _ " :
    string = " Geeks ▁ for ▁ Geeks "
    reverserWords ( string )

Index/key variables: i
Accumulator variables: st
Iterator variables: i
Python program:
from typing import List
MAXN = 100005
def makeNext ( arr : List [ int ] , n : int , nextBig : List [ int ] ) -> None :
    s = [ ]
    for i in range ( n - 1 , - 1 , - 1 ) :
        nextBig [ i ] = i
        while len ( s ) and s [ - 1 ] [ 0 ] < arr [ i ] :
            s . pop ( )
        if len ( s ) :
            nextBig [ i ] = s [ - 1 ] [ 1 ]
        s . append ( ( arr [ i ] , i ) )
def makePrev ( arr : List [ int ] , n : int , prevBig : List [ int ] ) -> None :
    s = [ ]
    for i in range ( n ) :
        prevBig [ i ] = - 1
        while ( len ( s ) and s [ - 1 ] [ 0 ] < arr [ i ] ) :
            s . pop ( )
        if ( len ( s ) ) :
            prevBig [ i ] = s [ - 1 ] [ 1 ]
        s . append ( ( arr [ i ] , i ) )
def wrapper ( arr : List [ int ] , n : int ) -> int :
    nextBig = [ 0 ] * MAXN
    prevBig = [ 0 ] * MAXN
    maxi = [ 0 ] * MAXN
    ans = 0
    makePrev ( arr , n , prevBig )
    makeNext ( arr , n , nextBig )
    for i in range ( n ) :
        if ( nextBig [ i ] != i ) :
            maxi [ nextBig [ i ] - i ] = max ( maxi [ nextBig [ i ] - i ] , i - prevBig [ i ] )
    for i in range ( n ) :
        ans += maxi [ i ]
    return ans
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 3 , 2 , 4 ]
    n = len ( arr )
    print ( wrapper ( arr , n ) )

Index/key variables: i, int
Accumulator variables: ans, s
Iterator variables: i
Python program:
INT_MIN = - 1000000
def printMaxOfMin ( arr , n ) :
    for k in range ( 1 , n + 1 ) :
        maxOfMin = INT_MIN ;
        for i in range ( n - k + 1 ) :
            min = arr [ i ]
            for j in range ( k ) :
                if ( arr [ i + j ] < min ) :
                    min = arr [ i + j ]
            if ( min > maxOfMin ) :
                maxOfMin = min
        print ( maxOfMin , end = " ▁ " )
arr = [ 10 , 20 , 30 , 50 , 10 , 70 , 30 ]
n = len ( arr )
printMaxOfMin ( arr , n )

Index/key variables: i
Iterator variables: i, j, k
Python program:
def printMaxOfMin ( arr , n ) :
    s = [ ]
    left = [ - 1 ] * ( n + 1 )
    right = [ n ] * ( n + 1 )
    for i in range ( n ) :
        while ( len ( s ) != 0 and arr [ s [ - 1 ] ] >= arr [ i ] ) :
            s . pop ( )
        if ( len ( s ) != 0 ) :
            left [ i ] = s [ - 1 ]
        s . append ( i )
    while ( len ( s ) != 0 ) :
        s . pop ( )
    for i in range ( n - 1 , - 1 , - 1 ) :
        while ( len ( s ) != 0 and arr [ s [ - 1 ] ] >= arr [ i ] ) :
            s . pop ( )
        if ( len ( s ) != 0 ) :
            right [ i ] = s [ - 1 ]
        s . append ( i )
    ans = [ 0 ] * ( n + 1 )
    for i in range ( n + 1 ) :
        ans [ i ] = 0
    for i in range ( n ) :
        Len = right [ i ] - left [ i ] - 1
        ans [ Len ] = max ( ans [ Len ] , arr [ i ] )
    for i in range ( n - 1 , 0 , - 1 ) :
        ans [ i ] = max ( ans [ i ] , ans [ i + 1 ] )
    for i in range ( 1 , n + 1 ) :
        print ( ans [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 10 , 20 , 30 , 50 , 10 , 70 , 30 ]
    n = len ( arr )
    printMaxOfMin ( arr , n )

Index/key variables: Len, i
Accumulator variables: s
Iterator variables: i
Python program:
def dfs ( tree , visit , ans , node ) :
    num = 0
    temp = 0
    visit [ node ] = 1
    for i in range ( len ( tree [ node ] ) ) :
        if ( visit [ tree [ node ] [ i ] ] == 0 ) :
            temp = dfs ( tree , visit , ans , tree [ node ] [ i ] )
            if ( temp % 2 ) :
                num += temp
            else :
                ans [ 0 ] += 1
    return num + 1
def minEdge ( tree , n ) :
    visit = [ 0 ] * ( n + 2 )
    ans = [ 0 ]
    dfs ( tree , visit , ans , 1 )
    return ans [ 0 ]
N = 12
n = 10
tree = [ [ ] for i in range ( n + 2 ) ]
tree [ 1 ] . append ( 3 )
tree [ 3 ] . append ( 1 )
tree [ 1 ] . append ( 6 )
tree [ 6 ] . append ( 1 )
tree [ 1 ] . append ( 2 )
tree [ 2 ] . append ( 1 )
tree [ 3 ] . append ( 4 )
tree [ 4 ] . append ( 3 )
tree [ 6 ] . append ( 8 )
tree [ 8 ] . append ( 6 )
tree [ 2 ] . append ( 7 )
tree [ 7 ] . append ( 2 )
tree [ 2 ] . append ( 5 )
tree [ 5 ] . append ( 2 )
tree [ 4 ] . append ( 9 )
tree [ 9 ] . append ( 4 )
tree [ 4 ] . append ( 10 )
tree [ 10 ] . append ( 4 )
print ( minEdge ( tree , n ) )

Index/key variables: i, node
Accumulator variables: num
Iterator variables: i
Python program:
def checkRedundancy ( Str ) :
    st = [ ]
    for ch in Str :
        if ( ch == ' ) ' ) :
            top = st [ - 1 ]
            st . pop ( )
            flag = True
            while ( top != ' ( ' ) :
                if ( top == ' + ' or top == ' - ' or top == ' * ' or top == ' / ' ) :
                    flag = False
                top = st [ - 1 ]
                st . pop ( )
            if ( flag == True ) :
                return True
        else :
            st . append ( ch )
    return False
def findRedundant ( Str ) :
    ans = checkRedundancy ( Str )
    if ( ans == True ) :
        print ( " Yes " )
    else :
        print ( " No " )
if __name__ == ' _ _ main _ _ ' :
    Str = " ( ( a + b ) ) "
    findRedundant ( Str )
    Str = " ( a + ( b ) / c ) "
    findRedundant ( Str )
    Str = " ( a + b * ( c - d ) ) "
    findRedundant ( Str )

Accumulator variables: st
Iterator variables: ch
Boolean variables: flag
Python program:
from collections import deque
def getIndex ( s , i ) :
    if s [ i ] != ' [ ' :
        return - 1
    d = deque ( )
    for k in range ( i , len ( s ) ) :
        if s [ k ] == ' [ ' :
            d . append ( s [ i ] )
        elif s [ k ] == ' ] ' :
            d . popleft ( )
        if not d :
            return k
    return - 1
def test ( s , i ) :
    matching_index = getIndex ( s , i )
    print ( s + " , ▁ " + str ( i ) + " : ▁ " + str ( matching_index ) )
def main ( ) :
    test ( " [ ABC [ 23 ] ] [89 ] " , 0 )
    test ( " [ ABC [ 23 ] ] [89 ] " , 4 )
    test ( " [ ABC [ 23 ] ] [89 ] " , 9 )
    test ( " [ ABC [ 23 ] ] [89 ] " , 1 )
if __name__ == " _ _ main _ _ " :
    main ( )

Index/key variables: i, k
Accumulator variables: d
Iterator variables: k
Python program:
def findDuplicateparenthesis ( string ) :
    Stack = [ ]
    for ch in string :
        if ch == ' ) ' :
            top = Stack . pop ( )
            elementsInside = 0
            while top != ' ( ' :
                elementsInside += 1
                top = Stack . pop ( )
            if elementsInside < 1 :
                return True
        else :
            Stack . append ( ch )
    return False
if __name__ == " _ _ main _ _ " :
    string = " ( ( ( a + ( b ) ) + ( c + d ) ) ) "
    if findDuplicateparenthesis ( string ) == True :
        print ( " Duplicate ▁ Found " )
    else :
        print ( " No ▁ Duplicates ▁ Found " )

Accumulator variables: Stack, elementsInside
Iterator variables: ch
Python program:
def nextGreater ( arr , n , next , order ) :
    S = [ ]
    for i in range ( n - 1 , - 1 , - 1 ) :
        while ( S != [ ] and ( arr [ S [ len ( S ) - 1 ] ] <= arr [ i ] if ( order == ' G ' ) else arr [ S [ len ( S ) - 1 ] ] >= arr [ i ] ) ) :
            S . pop ( )
        if ( S != [ ] ) :
            next [ i ] = S [ len ( S ) - 1 ]
        else :
            next [ i ] = - 1
        S . append ( i )
def nextSmallerOfNextGreater ( arr , n ) :
    NG = [ None ] * n
    RS = [ None ] * n
    nextGreater ( arr , n , NG , ' G ' )
    nextGreater ( arr , n , RS , ' S ' )
    for i in range ( n ) :
        if ( NG [ i ] != - 1 and RS [ NG [ i ] ] != - 1 ) :
            print ( arr [ RS [ NG [ i ] ] ] , end = " ▁ " )
        else :
            print ( " - 1" , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    arr = [ 5 , 1 , 9 , 2 , 5 , 1 , 7 ]
    n = len ( arr )
    nextSmallerOfNextGreater ( arr , n )

Index/key variables: i
Accumulator variables: S
Iterator variables: i
Python program:
class Node :
    def __init__ ( self , key ) :
        self . data = key
        self . left = None
        self . right = None
def convert_expression ( expression , i ) :
    if i >= len ( expression ) :
        return None
    root = Node ( expression [ i ] )
    i += 1
    if ( i < len ( expression ) and expression [ i ] == " ? " ) :
        root . left = convert_expression ( expression , i + 1 )
    elif i < len ( expression ) :
        root . right = convert_expression ( expression , i + 1 )
    return root
def print_tree ( root ) :
    if not root :
        return
    print ( root . data , end = ' ▁ ' )
    print_tree ( root . left )
    print_tree ( root . right )
if __name__ == " _ _ main _ _ " :
    string_expression = " a ? b ? c : d : e "
    root_node = convert_expression ( string_expression , 0 )
    print_tree ( root_node )

Index/key variables: i
Class/struct names: Node
Python program:
def countNumber ( n ) :
    result = 0
    s = [ ]
    for i in range ( 1 , 10 ) :
        if ( i <= n ) :
            s . append ( i )
            result += 1
        while len ( s ) != 0 :
            tp = s [ - 1 ]
            s . pop ( )
            for j in range ( tp % 10 , 10 ) :
                x = tp * 10 + j
                if ( x <= n ) :
                    s . append ( x )
                    result += 1
    return result
if __name__ == ' _ _ main _ _ ' :
    n = 15
    print ( countNumber ( n ) )

Accumulator variables: result, s
Iterator variables: i, j
Python program:
def removeConsecutiveSame ( v ) :
    n = len ( v )
    i = 0
    while ( i < n - 1 ) :
        if ( ( i + 1 ) < len ( v ) ) and ( v [ i ] == v [ i + 1 ] ) :
            v = v [ : i ]
            v = v [ : i ]
            if ( i > 0 ) :
                i -= 1
            n = n - 2
        else :
            i += 1
    return len ( v [ : i - 1 ] )
if __name__ == ' _ _ main _ _ ' :
    v = [ " tom " , " jerry " , " jerry " , " tom " ]
    print ( removeConsecutiveSame ( v ) )

Index/key variables: i
Python program:
def removeConsecutiveSame ( v ) :
    st = [ ]
    for i in range ( len ( v ) ) :
        if ( len ( st ) == 0 ) :
            st . append ( v [ i ] )
        else :
            Str = st [ - 1 ]
            if ( Str == v [ i ] ) :
                st . pop ( )
            else :
                st . append ( v [ i ] )
    return len ( st )
if __name__ == ' _ _ main _ _ ' :
    V = [ " ab " , " aa " , " aa " , " bcd " , " ab " ]
    print ( removeConsecutiveSame ( V ) )

Index/key variables: i
Accumulator variables: st
Iterator variables: i