dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int xorSumOfArray ( int arr [ ] , int n , int k , int count [ ] ) { int sum = 0 ; int p = 1 ; for ( int i = 0 ; i < 31 ; i ++ ) { int val = 0 ; if ( ( k & ( 1 << i ) ) != 0 ) { int not_set = n - count [ i ] ; val = ( ( not_set ) * p ) ; } else { val = ( count [ i ] * p ) ; } sum += val ; p = ( p * 2 ) ; } return sum ; } void sumOfXors ( int arr [ ] , int n , int queries [ ] , int q ) { int count [ 32 ] ; memset ( count , 0 , sizeof ( count ) ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < 31 ; j ++ ) { if ( arr [ i ] & ( 1 << j ) ) count [ j ] ++ ; } } for ( int i = 0 ; i < q ; i ++ ) { int k = queries [ i ] ; cout << xorSumOfArray ( arr , n , k , count ) << " ▁ " ; } } int main ( ) { int arr [ ] = { 5 , 2 , 3 } ; int queries [ ] = { 3 , 8 , 7 } ; int n = sizeof ( arr ) / sizeof ( int ) ; int q = sizeof ( queries ) / sizeof ( int ) ; sumOfXors ( arr , n , queries , q ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc, sum
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { struct Node * left , * right ; int key ; } ; Node * newNode ( int key ) { Node * temp = new Node ; temp -> key = key ; temp -> left = temp -> right = NULL ; return temp ; } void createFactorTree ( struct Node * * node_ref , int v ) { ( * node_ref ) = newNode ( v ) ; for ( int i = 2 ; i < v / 2 ; i ++ ) { if ( v % i != 0 ) continue ; createFactorTree ( & ( ( * node_ref ) -> left ) , i ) ; createFactorTree ( & ( ( * node_ref ) -> right ) , v / i ) ; return ; } } void printLevelOrder ( Node * root ) { if ( root == NULL ) return ; queue < Node * > q ; q . push ( root ) ; while ( q . empty ( ) == false ) { Node * node = q . front ( ) ; cout << node -> key << " ▁ " ; q . pop ( ) ; if ( node -> left != NULL ) q . push ( node -> left ) ; if ( node -> right != NULL ) q . push ( node -> right ) ; } } int main ( ) { int val = 48 ; struct Node * root = NULL ; createFactorTree ( & root , val ) ; cout << " Level ▁ order ▁ traversal ▁ of ▁ " " constructed ▁ factor ▁ tree " ; printLevelOrder ( root ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; void executeProcesses ( int A [ ] , int N , int K ) { priority_queue < int > pq ; for ( int i = 0 ; i < N ; i ++ ) { pq . push ( A [ i ] ) ; } int ans = 0 ; while ( ! pq . empty ( ) && K > 0 ) { int top = pq . top ( ) ; pq . pop ( ) ; ans ++ ; K = K - top ; top = top / 2 ; pq . push ( top ) ; } cout << ans ; } int main ( ) { int A [ ] = { 3 , 1 , 7 , 4 , 2 } ; int K = 15 ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; executeProcesses ( A , N , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define M  3
#define N  3
void findHeightMatrixUtil ( int mat [ ] [ N ] , int height [ M ] [ N ] ) { queue < pair < int , int > > q ; int vis [ M ] [ N ] = { 0 } ; for ( int i = 0 ; i < M ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { if ( mat [ i ] [ j ] == 1 ) { q . push ( { i , j } ) ; height [ i ] [ j ] = 0 ; vis [ i ] [ j ] = 1 ; } } } while ( q . empty ( ) == 0 ) { pair < int , int > k = q . front ( ) ; q . pop ( ) ; int x = k . first , y = k . second ; if ( x > 0 && vis [ x - 1 ] [ y ] == 0 ) { height [ x - 1 ] [ y ] = height [ x ] [ y ] + 1 ; vis [ x - 1 ] [ y ] = 1 ; q . push ( { x - 1 , y } ) ; } if ( y > 0 && vis [ x ] [ y - 1 ] == 0 ) { height [ x ] [ y - 1 ] = height [ x ] [ y ] + 1 ; vis [ x ] [ y - 1 ] = 1 ; q . push ( { x , y - 1 } ) ; } if ( x < M - 1 && vis [ x + 1 ] [ y ] == 0 ) { height [ x + 1 ] [ y ] = height [ x ] [ y ] + 1 ; vis [ x + 1 ] [ y ] = 1 ; q . push ( { x + 1 , y } ) ; } if ( y < N - 1 && vis [ x ] [ y + 1 ] == 0 ) { height [ x ] [ y + 1 ] = height [ x ] [ y ] + 1 ; vis [ x ] [ y + 1 ] = 1 ; q . push ( { x , y + 1 } ) ; } } } void findHeightMatrix ( int mat [ ] [ N ] ) { int height [ M ] [ N ] ; findHeightMatrixUtil ( mat , height ) ; for ( int i = 0 ; i < M ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) cout << height [ i ] [ j ] << " ▁ " ; cout << endl ; } } int main ( ) { int mat [ ] [ N ] = { { 0 , 0 } , { 0 , 1 } } ; findHeightMatrix ( mat ) ; return 0 ; }

Index/key variables: M, N, i, j, x, y
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { struct Node * left , * right ; int key ; } ; Node * newNode ( int key ) { Node * temp = new Node ; temp -> key = key ; temp -> left = temp -> right = NULL ; return temp ; } Node * insertNode ( Node * node , int key ) { if ( node == NULL ) return newNode ( key ) ; if ( key < node -> key ) node -> left = insertNode ( node -> left , key ) ; else if ( key > node -> key ) node -> right = insertNode ( node -> right , key ) ; return node ; } void getIntermediateNodes ( Node * root , vector < int > & interNodes , int node1 , int node2 ) { if ( root == NULL ) return ; getIntermediateNodes ( root -> left , interNodes , node1 , node2 ) ; if ( root -> key <= node2 and root -> key >= node1 ) { interNodes . push_back ( root -> key ) ; } getIntermediateNodes ( root -> right , interNodes , node1 , node2 ) ; } float findMedian ( Node * root , int node1 , int node2 ) { vector < int > interNodes ; getIntermediateNodes ( root , interNodes , node1 , node2 ) ; int nSize = interNodes . size ( ) ; return ( nSize % 2 == 1 ) ? ( float ) interNodes [ nSize / 2 ] : ( float ) ( interNodes [ ( nSize - 1 ) / 2 ] + interNodes [ nSize / 2 ] ) / 2 ; } int main ( ) { struct Node * root = NULL ; root = insertNode ( root , 8 ) ; insertNode ( root , 3 ) ; insertNode ( root , 1 ) ; insertNode ( root , 6 ) ; insertNode ( root , 4 ) ; insertNode ( root , 11 ) ; insertNode ( root , 15 ) ; cout << findMedian ( root , 3 , 11 ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; void computeTotient ( int N , int phi [ ] ) { for ( int p = 2 ; p <= N ; p ++ ) { if ( phi [ p ] == p ) { phi [ p ] = p - 1 ; for ( int i = 2 * p ; i <= N ; i += p ) { phi [ i ] = ( phi [ i ] / p ) * ( p - 1 ) ; } } } } void countPairs ( int N ) { int cnt_type1 = 0 , cnt_type2 = 0 ; int half_N = N / 2 ; cnt_type1 = ( half_N * ( half_N - 1 ) ) / 2 ; int phi [ N + 1 ] ; for ( int i = 1 ; i <= N ; i ++ ) { phi [ i ] = i ; } computeTotient ( N , phi ) ; for ( int i = ( N / 2 ) + 1 ; i <= N ; i ++ ) cnt_type2 += ( i - phi [ i ] - 1 ) ; cout << cnt_type1 + cnt_type2 ; } int main ( ) { int N = 6 ; countPairs ( N ) ; return 0 ; }

Index/key variables: i, p
Accumulator variables: cnt_type2, i, p, stdc
Iterator variables: i, p
C++ program:
#include <bits/stdc++.h>
using namespace std ; int ans = INT_MAX ; int mini = INT_MAX ; void findClosestTarget ( int i , int curr , int B [ ] , int M , int K ) { if ( abs ( curr - K ) < mini ) { mini = abs ( curr - K ) ; ans = curr ; } if ( abs ( curr - K ) == mini ) { ans = min ( ans , curr ) ; } if ( i >= M ) return ; findClosestTarget ( i + 1 , curr + B [ i ] , B , M , K ) ; findClosestTarget ( i + 1 , curr + 2 * B [ i ] , B , M , K ) ; findClosestTarget ( i + 1 , curr , B , M , K ) ; } int findClosest ( int A [ ] , int B [ ] , int N , int M , int K ) { for ( int i = 0 ; i < N ; i ++ ) { findClosestTarget ( 0 , A [ i ] , B , M , K ) ; } return ans ; } int main ( ) { int A [ ] = { 2 , 3 } ; int B [ ] = { 4 , 5 , 30 } ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; int M = sizeof ( B ) / sizeof ( B [ 0 ] ) ; int K = 18 ; cout << findClosest ( A , B , N , M , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findNode ( map < int , int > mp , int n ) { int a [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = mp [ i + 1 ] ; } int count0 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] == 0 ) { count0 ++ ; } } count0 -= 1 ; if ( count0 <= floor ( ( ( double ) n ) / ( ( double ) 2 ) ) ) { cout << " Yes " ; } else cout << " No " ; } int main ( ) { int N = 3 ; map < int , int > mp ; mp [ 1 ] = 0 ; mp [ 2 ] = 2 ; mp [ 3 ] = 0 ; findNode ( mp , N ) ; }

Index/key variables: i, n
Accumulator variables: count0, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int convert ( vector < int > p ) { int ans = 0 ; for ( int i : p ) { ans = ( ans << 1 ) | i ; } return ans ; } int count ( int num ) { int ans = 0 ; while ( num > 0 ) { ans += num & 1 ; num >>= 1 ; } return ans ; } void checkGoodMatrix ( vector < vector < int > > mat ) { vector < int > P ; vector < int > S ; vector < int > MR ; vector < int > MC ; for ( int i = 0 ; i < mat . size ( ) ; i ++ ) { for ( int j = 0 ; j < mat [ 0 ] . size ( ) ; j ++ ) { if ( i == j ) P . push_back ( mat [ i ] [ j ] ) ; if ( i + j == mat . size ( ) - 1 ) S . push_back ( mat [ i ] [ j ] ) ; if ( i == floor ( ( mat . size ( ) - 1 ) / 2 ) ) MR . push_back ( mat [ i ] [ j ] ) ; if ( j == floor ( ( mat . size ( ) - 1 ) / 2 ) ) MC . push_back ( mat [ i ] [ j ] ) ; } } reverse ( S . begin ( ) , S . end ( ) ) ; int P0 = convert ( P ) ; int S0 = convert ( S ) ; int MR0 = convert ( MR ) ; int MC0 = convert ( MC ) ; int setBitsPS = count ( ( P0 & S0 ) ) ; int setBitsMM = count ( ( MR0 & MC0 ) ) ; if ( setBitsPS > setBitsMM ) cout << " Yes " ; else cout << " No " ; } int main ( ) { vector < vector < int > > mat = { { 1 , 0 , 1 } , { 0 , 0 , 1 } , { 0 , 1 , 1 } } ; checkGoodMatrix ( mat ) ; }

Index/key variables: i, j
Accumulator variables: ans, i, j, stdc
Iterator variables: i, j
C++ program:
#include " bits / stdc + + . h "
using namespace std ; void assignValues ( int Edges [ ] [ 2 ] , int n ) { vector < int > tree [ n + 1 ] ; for ( int i = 0 ; i < n - 1 ; i ++ ) { int u = Edges [ i ] [ 0 ] ; int v = Edges [ i ] [ 1 ] ; tree [ u ] . push_back ( v ) ; tree [ v ] . push_back ( u ) ; } vector < bool > visited ( n + 1 , false ) ; vector < int > answer ( n + 1 ) ; int K = 1 ; queue < int > q ; q . push ( 1 ) ; answer [ 1 ] = K ; while ( ! q . empty ( ) ) { int node = q . front ( ) ; q . pop ( ) ; visited [ node ] = true ; K = ( ( answer [ node ] == 1 ) ? 2 : 1 ) ; for ( auto child : tree [ node ] ) { if ( ! visited [ child ] ) { q . push ( child ) ; answer [ child ] = K ; } } } for ( int i = 1 ; i <= n ; i ++ ) { cout << answer [ i ] << " ▁ " ; } } int main ( ) { int N = 11 ; int Edges [ ] [ 2 ] = { { 1 , 2 } , { 1 , 3 } , { 1 , 4 } , { 1 , 5 } , { 2 , 6 } , { 2 , 10 } , { 10 , 11 } , { 3 , 7 } , { 4 , 8 } , { 5 , 9 } } ; assignValues ( Edges , N ) ; return 0 ; }

Index/key variables: child, i, node, u, v
Accumulator variables: i
Iterator variables: child, i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int numoffbt ( int arr [ ] , int n ) { int maxvalue = INT_MIN , minvalue = INT_MAX ; for ( int i = 0 ; i < n ; i ++ ) { maxvalue = max ( maxvalue , arr [ i ] ) ; minvalue = min ( minvalue , arr [ i ] ) ; } int mark [ maxvalue + 2 ] ; int value [ maxvalue + 2 ] ; memset ( mark , 0 , sizeof ( mark ) ) ; memset ( value , 0 , sizeof ( value ) ) ; for ( int i = 0 ; i < n ; i ++ ) { mark [ arr [ i ] ] = 1 ; value [ arr [ i ] ] = 1 ; } int ans = 0 ; for ( int i = minvalue ; i <= maxvalue ; i ++ ) { if ( mark [ i ] ) { for ( int j = i + i ; j <= maxvalue && j / i <= i ; j += i ) { if ( ! mark [ j ] ) continue ; value [ j ] = value [ j ] + ( value [ i ] * value [ j / i ] ) ; if ( i != j / i ) value [ j ] = value [ j ] + ( value [ i ] * value [ j / i ] ) ; } } ans += value [ i ] ; } return ans ; } int main ( ) { int arr [ ] = { 2 , 3 , 4 , 6 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << numoffbt ( arr , n ) << endl ; return 0 ; }

Index/key variables: i, j
Accumulator variables: ans, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
#define limit  100000
using namespace std ; bool prime [ limit + 1 ] ; void sieve ( ) { memset ( prime , true , sizeof ( prime ) ) ; for ( int p = 2 ; p * p <= limit ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * p ; i <= limit ; i += p ) prime [ i ] = false ; } } } int findOperations ( int arr [ ] , int n ) { sieve ( ) ; int minm = INT_MAX ; for ( int i = 0 ; i < n ; i ++ ) { minm = min ( minm , arr [ i ] ) ; } int val = minm ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == minm + 1 ) { val = minm - 2 ; break ; } } int cnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int D = arr [ i ] - val ; if ( D == 0 ) { continue ; } else if ( prime [ D ] == true ) { cnt += 1 ; } else if ( D % 2 == 0 ) { cnt += 2 ; } else { if ( prime [ D - 2 ] == true ) { cnt += 2 ; } else { cnt += 3 ; } } } return cnt ; } int main ( ) { int arr [ ] = { 7 , 10 , 4 , 5 } ; int N = 4 ; cout << findOperations ( arr , N ) ; return 0 ; }

Index/key variables: D, i, p
Accumulator variables: cnt, i, p, stdc
Iterator variables: i, p
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printUnique ( vector < long long > lis ) { reverse ( lis . begin ( ) , lis . end ( ) ) ; for ( long long i : lis ) cout << i << " ▁ " ; } void checkUnique ( string st ) { vector < long long > lis ; long long res = 0 ; long long N = stoll ( st ) ; vector < long long > cnt ( 10 , 0 ) , cnt1 ( 10 , 0 ) ; while ( N > 0 ) { long long rem = N % 10 ; cnt [ rem ] += 1 ; N = N / 10 ; } N = stoll ( st ) ; while ( N > 0 ) { long long rem = N % 10 ; if ( cnt1 [ rem ] == 0 ) { if ( cnt [ rem ] == 1 ) lis . push_back ( rem ) ; } cnt1 [ rem ] = 1 ; N = N / 10 ; } printUnique ( lis ) ; } void combineArray ( vector < long long > lis ) { string st = " " ; for ( long long el : lis ) { string ee = to_string ( el ) ; st = st + ee ; } checkUnique ( st ) ; } int main ( ) { vector < long long > arr = { 122 , 474 , 612 , 932 } ; combineArray ( arr ) ; return 0 ; }

Index/key variables: rem
Accumulator variables: stdc
Iterator variables: el, i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int calcScore ( vector < int > p , int arr [ ] , int N ) { int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { ans += ( p [ i ] & arr [ i ] ) ; } return ans ; } int getMaxUtil ( vector < int > p , int arr [ ] , int ans , bool chosen [ ] , int N ) { if ( p . size ( ) == N ) { ans = max ( ans , calcScore ( p , arr , N ) ) ; return ans ; } for ( int i = 0 ; i < N ; i ++ ) { if ( chosen [ i ] ) { continue ; } chosen [ i ] = true ; p . push_back ( i ) ; ans = getMaxUtil ( p , arr , ans , chosen , N ) ; chosen [ i ] = false ; p . pop_back ( ) ; } return ans ; } void getMax ( int arr [ ] , int N ) { int ans = 0 ; bool chosen [ N ] ; for ( int i = 0 ; i < N ; i ++ ) chosen [ i ] = false ; vector < int > p ; int res = getMaxUtil ( p , arr , ans , chosen , N ) ; cout << res ; } int main ( ) { int arr [ ] = { 4 , 2 , 3 , 6 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; getMax ( arr , N ) ; return 0 ; }

Index/key variables: N, i
Accumulator variables: ans, i, stdc
Iterator variables: i
C++ program:
#include <iostream>
#include <bits/stdc++.h>
using namespace std ; int setBitCount ( int n ) { int ans = 0 ; while ( n ) { ans += n & 1 ; n >>= 1 ; } return ans ; } int getSum ( int * arr , int n ) { map < int , int > mp ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int key = setBitCount ( arr [ i ] ) ; mp [ key ] += 1 ; } for ( int i = 0 ; i < n ; i ++ ) { int key = setBitCount ( arr [ i ] ) ; if ( mp [ key ] == 1 ) ans += arr [ i ] ; } cout << ans ; } int main ( ) { int arr [ 5 ] = { 8 , 3 , 7 , 5 , 3 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; getSum ( arr , n ) ; return 0 ; }

Index/key variables: i, key
Accumulator variables: ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findSplit ( int arr [ ] , int N ) { vector < int > sum ( N ) ; for ( int i = 0 ; i < N ; i ++ ) { sum [ i ] = arr [ i ] ; } for ( int i = 1 ; i < N ; i ++ ) { sum [ i ] += sum [ i - 1 ] ; } for ( int l = 1 ; l <= N - 4 ; l ++ ) { for ( int r = l + 2 ; r <= N - 2 ; r ++ ) { int lsum = 0 , rsum = 0 , msum = 0 ; lsum = sum [ l - 1 ] ; msum = sum [ r - 1 ] - sum [ l ] ; rsum = sum [ N - 1 ] - sum [ r ] ; if ( lsum == rsum && rsum == msum ) { cout << l << " ▁ " << r << endl ; return ; } } } cout << -1 << endl ; } int main ( ) { int arr [ ] = { 2 , 5 , 12 , 7 , 19 , 4 , 3 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; findSplit ( arr , N ) ; return 0 ; }

Index/key variables: i, l, r
Accumulator variables: i, l, r, stdc
Iterator variables: i, l, r
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findSplit ( int arr [ ] , int N ) { int l = 1 , r = N - 2 ; int lsum , msum , rsum ; vector < int > sum ( N ) ; sum [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { sum [ i ] = sum [ i - 1 ] + arr [ i ] ; } while ( l < r ) { lsum = sum [ l - 1 ] ; msum = sum [ r - 1 ] - sum [ l ] ; rsum = sum [ N - 1 ] - sum [ r ] ; if ( lsum == msum and msum == rsum ) { cout << l << " ▁ " << r << endl ; return ; } if ( lsum < rsum ) l ++ ; else if ( lsum > rsum ) r -- ; else { l ++ ; r -- ; } } cout << -1 << endl ; } int main ( ) { int arr [ ] = { 2 , 5 , 12 , 7 , 19 , 4 , 3 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; findSplit ( arr , N ) ; return 0 ; }

Index/key variables: i, l, r
Accumulator variables: i, l, r, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
struct Node { int data ; struct Node * left , * right ; } ; struct Node * newNode ( int data ) { struct Node * node = new Node ; node -> data = data ; node -> left = node -> right = NULL ; return ( node ) ; } int countRec ( struct Node * root , int * pcount ) { if ( root == NULL ) return 0 ; int c = countRec ( root -> left , pcount ) ; c += countRec ( root -> right , pcount ) ; if ( root -> data % 2 == 0 ) c += 1 ; if ( c % 2 != 0 ) ( * pcount ) ++ ; return c ; } int countSubtrees ( Node * root ) { int count = 0 ; int * pcount = & count ; countRec ( root , pcount ) ; return count ; } int main ( ) { struct Node * root = newNode ( 2 ) ; root -> left = newNode ( 1 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 10 ) ; root -> right -> left = newNode ( 8 ) ; root -> right -> right = newNode ( 5 ) ; root -> left -> right -> left = newNode ( 6 ) ; printf ( " Count ▁ = ▁ % d " , countSubtrees ( root ) ) ; return 0 ; }

Accumulator variables: c, stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; Node * temp = new Node ; Node * newNode ( int data ) { Node * temp = new Node ; temp -> data = data ; temp -> left = temp -> right = NULL ; return temp ; } Node * leftMostNode ( Node * node ) { while ( node != NULL && node -> left != NULL ) node = node -> left ; return node ; } Node * rightMostNode ( Node * node ) { while ( node != NULL && node -> right != NULL ) node = node -> right ; return node ; } Node * findInorderRecursive ( Node * root , Node * x ) { if ( ! root ) return NULL ; if ( root == x || ( temp = findInorderRecursive ( root -> left , x ) ) || ( temp = findInorderRecursive ( root -> right , x ) ) ) { if ( temp ) { if ( root -> left == temp ) { cout << " Inorder ▁ Successor ▁ of ▁ " << x -> data ; cout << " ▁ is ▁ " << root -> data << " STRNEWLINE " ; return NULL ; } } return root ; } return NULL ; } void inorderSuccesor ( Node * root , Node * x ) { if ( x -> right != NULL ) { Node * inorderSucc = leftMostNode ( x -> right ) ; cout << " Inorder ▁ Successor ▁ of ▁ " << x -> data << " ▁ is ▁ " ; cout << inorderSucc -> data << " STRNEWLINE " ; } if ( x -> right == NULL ) { int f = 0 ; Node * rightMost = rightMostNode ( root ) ; if ( rightMost == x ) cout << " No ▁ inorder ▁ successor ! ▁ Right ▁ most ▁ node . STRNEWLINE " ; else findInorderRecursive ( root , x ) ; } } int main ( ) { Node * 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 ) ; inorderSuccesor ( root , root -> right ) ; inorderSuccesor ( root , root -> left -> left ) ; inorderSuccesor ( root , root -> right -> right ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * left ; struct Node * right ; Node ( int val ) { data = val ; left = NULL ; right = NULL ; } } ; int main ( ) { struct Node * root = new Node ( 1 ) ; root -> left = new Node ( 2 ) ; root -> right = new Node ( 3 ) ; root -> left -> left = new Node ( 4 ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; Node * left , * right ; } ; Node * newNode ( int item ) { Node * temp = new Node ; temp -> data = item ; temp -> left = temp -> right = NULL ; return temp ; } int findDistance ( Node * root , int x ) { if ( root == NULL ) return -1 ; int dist = -1 ; if ( ( root -> data == x ) || ( dist = findDistance ( root -> left , x ) ) >= 0 || ( dist = findDistance ( root -> right , x ) ) >= 0 ) return dist + 1 ; return dist ; } int main ( ) { Node * root = newNode ( 5 ) ; root -> left = newNode ( 10 ) ; root -> right = newNode ( 15 ) ; root -> left -> left = newNode ( 20 ) ; root -> left -> right = newNode ( 25 ) ; root -> left -> right -> right = newNode ( 45 ) ; root -> right -> left = newNode ( 30 ) ; root -> right -> right = newNode ( 35 ) ; cout << findDistance ( root , 45 ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
struct Node { int data ; Node * left , * right , * parent ; } ; Node * newNode ( int item , Node * parent ) { Node * temp = new Node ; temp -> data = item ; temp -> left = temp -> right = NULL ; temp -> parent = parent ; return temp ; } Node * findRightSibling ( Node * node , int level ) { if ( node == NULL node -> parent == NULL ) return NULL ; while ( node -> parent -> right == node || ( node -> parent -> right == NULL && node -> parent -> left == node ) ) { if ( node -> parent == NULL node -> parent -> parent == NULL ) return NULL ; node = node -> parent ; level -- ; } node = node -> parent -> right ; if ( node == NULL ) return NULL ; while ( level < 0 ) { if ( node -> left != NULL ) node = node -> left ; else if ( node -> right != NULL ) node = node -> right ; else break ; level ++ ; } if ( level == 0 ) return node ; return findRightSibling ( node , level ) ; } int main ( ) { Node * root = newNode ( 1 , NULL ) ; root -> left = newNode ( 2 , root ) ; root -> right = newNode ( 3 , root ) ; root -> left -> left = newNode ( 4 , root -> left ) ; root -> left -> right = newNode ( 6 , root -> left ) ; root -> left -> left -> left = newNode ( 7 , root -> left -> left ) ; root -> left -> left -> left -> left = newNode ( 10 , root -> left -> left -> left ) ; root -> left -> right -> right = newNode ( 9 , root -> left -> right ) ; root -> right -> right = newNode ( 5 , root -> right ) ; root -> right -> right -> right = newNode ( 8 , root -> right -> right ) ; root -> right -> right -> right -> right = newNode ( 12 , root -> right -> right -> right ) ; Node * res = findRightSibling ( root -> left -> left -> left -> left , 0 ) ; if ( res == NULL ) printf ( " No ▁ right ▁ sibling " ) ; else printf ( " % d " , res -> data ) ; return 0 ; }

Accumulator variables: level, stdc
Class/struct names: Node