dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; # define NO_OF_CHARS  256
void badCharHeuristic ( string str , int size , int badchar [ NO_OF_CHARS ] ) { int i ; for ( i = 0 ; i < NO_OF_CHARS ; i ++ ) badchar [ i ] = -1 ; for ( i = 0 ; i < size ; i ++ ) badchar [ ( int ) str [ i ] ] = i ; } void search ( string txt , string pat ) { int m = pat . size ( ) ; int n = txt . size ( ) ; int badchar [ NO_OF_CHARS ] ; badCharHeuristic ( pat , m , badchar ) ; while ( s <= ( n - m ) ) { int j = m - 1 ; while ( j >= 0 && pat [ j ] == txt [ s + j ] ) j -- ; if ( j < 0 ) { cout << " pattern ▁ occurs ▁ at ▁ shift ▁ = ▁ " << s << endl ; s += ( s + m < n ) ? m - badchar [ txt [ s + m ] ] : 1 ; } else s += max ( 1 , j - badchar [ txt [ s + j ] ] ) ; } } int main ( ) { string txt = " ABAAABCD " ; string pat = " ABC " ; search ( txt , pat ) ; return 0 ; }

Index/key variables: NO_OF_CHARS, i, j
Accumulator variables: i, j, s, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; Node * left , * right ; Node ( int data ) { this -> data = data ; this -> left = NULL ; this -> right = NULL ; } } ; int sumMaxLevelRec ( Node * node , int max ) { if ( node == NULL ) return 0 ; if ( max == 1 ) return node -> data ; return sumMaxLevelRec ( node -> left , max - 1 ) + sumMaxLevelRec ( node -> right , max - 1 ) ; } int maxDepth ( Node * node ) { if ( node == NULL ) return 0 ; return 1 + max ( maxDepth ( node -> left ) , maxDepth ( node -> right ) ) ; } int sumMaxLevel ( Node * root ) { int MaxDepth = maxDepth ( root ) ; return sumMaxLevelRec ( root , MaxDepth ) ; } int main ( ) { Node * root = new Node ( 1 ) ; root -> left = new Node ( 2 ) ; root -> right = new Node ( 3 ) ; root -> left -> left = new Node ( 4 ) ; root -> left -> right = new Node ( 5 ) ; root -> right -> left = new Node ( 6 ) ; root -> right -> right = new Node ( 7 ) ; cout << ( sumMaxLevel ( root ) ) << endl ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; void SumofDistances ( string s ) { vector < int > v [ 26 ] ; for ( int i = 0 ; i < s . size ( ) ; i ++ ) { v [ s [ i ] - ' a ' ] . push_back ( i ) ; } int ans = 0 ; for ( int i = 0 ; i < 26 ; i ++ ) { int sum = 0 ; for ( int j = 0 ; j < v [ i ] . size ( ) ; j ++ ) { sum += v [ i ] [ j ] ; } for ( int j = 0 ; j < v [ i ] . size ( ) ; j ++ ) { sum -= v [ i ] [ j ] ; ans += ( sum - ( v [ i ] . size ( ) - 1 - j ) * ( v [ i ] [ j ] ) ) ; } } cout << ans ; } int main ( ) { string s = " ababa " ; SumofDistances ( s ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: ans, i, j, stdc, sum
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findOperations ( string A , string B , int N ) { int operations = 0 ; vector < int > ops ; bool invert = false ; for ( int i = N - 1 ; i >= 0 ; i -- ) { if ( A [ i ] != B [ i ] ) { if ( ! invert ) { operations ++ ; ops . push_back ( i + 1 ) ; invert = true ; } } else { if ( invert ) { operations ++ ; ops . push_back ( i + 1 ) ; invert = false ; } } } cout << operations << endl ; if ( operations != 0 ) { for ( auto x : ops ) cout << x << " ▁ " ; } } int main ( ) { string A = "001" , B = "000" ; int N = A . size ( ) ; findOperations ( A , B , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, operations, stdc
Iterator variables: i, x
Boolean variables: invert
C++ program:
#include <bits/stdc++.h>
using namespace std ; void countFrequency ( string S , int N ) { int freq [ 26 ] = { 0 } ; for ( int i = 0 ; i < N ; i ++ ) { freq [ S [ i ] - ' a ' ] ++ ; } for ( int i = 0 ; i < 26 ; i ++ ) { if ( freq [ i ] == 0 ) continue ; int lg = log2 ( freq [ i ] ) ; int a = pow ( 2 , lg ) ; if ( a == freq [ i ] ) { while ( freq [ i ] -- ) cout << ( char ) ( i + ' a ' ) ; } } } int main ( ) { string S = " aaacbb " ; int N = S . size ( ) ; countFrequency ( S , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct treeNode { int square_sum ; } ; void buildTree ( string s , treeNode * tree , int start , int end , int treeNode ) { if ( start == end ) { tree [ treeNode ] . square_sum = pow ( s [ start ] - ' a ' + 1 , 2 ) ; return ; } int mid = start + ( ( end - start ) / 2 ) ; buildTree ( s , tree , start , mid , 2 * treeNode ) ; buildTree ( s , tree , mid + 1 , end , 1 + 2 * treeNode ) ; tree [ treeNode ] . square_sum = tree [ ( 2 * treeNode ) ] . square_sum + tree [ ( 2 * treeNode ) + 1 ] . square_sum ; } int querySquareSum ( treeNode * tree , int start , int end , int treeNode , int l , int r ) { if ( ( l > end ) || ( r < start ) ) { return 0 ; } if ( ( l <= start ) && ( r >= end ) ) { return tree [ treeNode ] . square_sum ; } int mid = start + ( ( end - start ) / 2 ) ; int X = querySquareSum ( tree , start , mid , 2 * treeNode , l , r ) ; int Y = + querySquareSum ( tree , mid + 1 , end , 1 + 2 * treeNode , l , r ) ; return X + Y ; } void updateTree ( string s , treeNode * tree , int start , int end , int treeNode , int idx , char X ) { if ( ( start == end ) && ( idx == start ) ) { s [ idx ] = X ; tree [ treeNode ] . square_sum = pow ( X - ' a ' + 1 , 2 ) ; return ; } int mid = start + ( ( end - start ) / 2 ) ; if ( idx <= mid ) { updateTree ( s , tree , start , mid , ( 2 * treeNode ) , idx , X ) ; } else { updateTree ( s , tree , mid + 1 , end , ( 2 * treeNode ) + 1 , idx , X ) ; } tree [ treeNode ] . square_sum = tree [ ( 2 * treeNode ) ] . square_sum + tree [ ( 2 * treeNode ) + 1 ] . square_sum ; } void PerformQuery ( string S , vector < vector < string > > Q ) { int n = S . size ( ) ; treeNode * tree = new treeNode [ ( 4 * n ) + 1 ] ; for ( int i = 0 ; i <= ( 4 * n ) ; i = i + 1 ) { tree [ i ] . square_sum = 0 ; } buildTree ( S , tree , 0 , n - 1 , 1 ) ; for ( int i = 0 ; i < Q . size ( ) ; i ++ ) { if ( Q [ i ] [ 0 ] == " S " ) { int L = stoi ( Q [ i ] [ 1 ] ) ; int R = stoi ( Q [ i ] [ 2 ] ) ; cout << querySquareSum ( tree , 0 , n - 1 , 1 , L , R ) << endl ; } else if ( Q [ i ] [ 0 ] == " U " ) { int I = stoi ( Q [ i ] [ 1 ] ) ; updateTree ( S , tree , 0 , n - 1 , 1 , I , Q [ i ] [ 2 ] [ 0 ] ) ; } } } int main ( ) { string S = " geeksforgeeks " ; vector < vector < string > > Q = { { " S " , "0" , "2" } , { " S " , "1" , "2" } , { " U " , "1" , " a " } , { " S " , "0" , "2" } , { " S " , "4" , "5" } } ; PerformQuery ( S , Q ) ; }

Index/key variables: i, idx, start, treeNode
Accumulator variables: i, stdc
Iterator variables: i
Class/struct names: treeNode
C++ program:
#include <bits/stdc++.h>
using namespace std ; void lcsBySwapping ( string A , string B ) { int N = A . size ( ) ; int M = B . size ( ) ; int freq [ 26 ] ; memset ( freq , 0 , sizeof ( freq ) ) ; for ( int i = 0 ; i < A . size ( ) ; i ++ ) { freq [ A [ i ] - ' a ' ] += 1 ; } for ( int i = 0 ; i < B . size ( ) ; i ++ ) { freq [ B [ i ] - ' a ' ] += 1 ; } int cnt = 0 ; for ( int i = 0 ; i < 26 ; i ++ ) { cnt += freq [ i ] / 2 ; } cout << min ( cnt , min ( N , M ) ) ; } int main ( ) { string A = " abdeff " ; string B = " abbet " ; lcsBySwapping ( A , B ) ; return 0 ; }

Index/key variables: i
Accumulator variables: cnt, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maximumLengthSubsequence ( string str ) { unordered_map < char , int > mp ; for ( char ch : str ) { mp [ ch ] ++ ; } int ans = 0 ; for ( char ch : str ) { if ( mp . count ( ch - 1 ) ) { int curr_max = mp [ ch ] + mp [ ch - 1 ] ; ans = max ( ans , curr_max ) ; } } cout << ans ; } int main ( ) { string S = " acbbebcg " ; maximumLengthSubsequence ( S ) ; return 0 ; }

Index/key variables: ch
Accumulator variables: stdc
Iterator variables: ch
C++ program:
#include <bits/stdc++.h>
using namespace std ; void countOperations ( string X , string Y , int K ) { int count = 0 ; for ( int i = 0 ; i < X . length ( ) ; i ++ ) { int c = 0 ; if ( X [ i ] == Y [ i ] ) continue ; else if ( X [ i ] < Y [ i ] ) { if ( ( Y [ i ] - X [ i ] ) >= K ) { c = ( Y [ i ] - X [ i ] ) / K ; } c += ( Y [ i ] - X [ i ] ) % K ; } else { int t = 90 - X [ i ] ; t += Y [ i ] - 65 + 1 ; if ( t >= K ) c = t / K ; c += ( t % K ) ; } count += c ; } cout << count << endl ; } int main ( ) { string X = " ABCT " , Y = " PBDI " ; int K = 6 ; countOperations ( X , Y , K ) ; }

Index/key variables: i
Accumulator variables: c, count, i, stdc, t
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minimumSwaps ( string s , int l , int r , int k ) { int n = s . length ( ) ; int tot_ones = 0 , tot_zeros = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s [ i ] == '1' ) tot_ones ++ ; else tot_zeros ++ ; } int ones = 0 , zeros = 0 , sum = 0 ; for ( int i = l - 1 ; i < r ; i ++ ) { if ( s [ i ] == '1' ) { ones ++ ; sum ++ ; } else zeros ++ ; } int rem_ones = tot_ones - ones ; int rem_zeros = tot_zeros - zeros ; if ( k >= sum ) { int rem = k - sum ; if ( zeros >= rem && rem_ones >= rem ) return rem ; } else if ( k < sum ) { int rem = sum - k ; if ( ones >= rem && rem_zeros >= rem ) return rem ; } return -1 ; } int main ( ) { string S = "110011111000101" ; int L = 5 , R = 8 , K = 2 ; cout << minimumSwaps ( S , L , R , K ) ; }

Index/key variables: i
Accumulator variables: i, ones, stdc, sum, tot_ones, tot_zeros, zeros
Iterator variables: i
C++ program:
#include " bits / stdc + + . h "
using namespace std ; vector < int > Ans ; void populateNumber ( ) { Ans . push_back ( 2 ) ; Ans . push_back ( 5 ) ; long long int x = 5 ; while ( x < 1000000000001 ) { x *= 2 ; Ans . push_back ( x ) ; x = x * 2 + 1 ; Ans . push_back ( x ) ; } } string checkString ( long long int N ) { populateNumber ( ) ; for ( auto & it : Ans ) { if ( it == N ) { return " Yes " ; } } return " No " ; } int main ( ) { long long int N = 5 ; cout << checkString ( N ) ; return 0 ; }

Accumulator variables: x
C++ program:
#include <bits/stdc++.h>
using namespace std ; void deleteSubseq ( string s ) { int N = s . size ( ) ; stack < char > roundStk ; stack < char > squareStk ; int roundCount = 0 ; int squareCount = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( s [ i ] == ' [ ' ) { squareStk . push ( s [ i ] ) ; } else if ( s [ i ] == ' ] ' ) { if ( squareStk . size ( ) != 0 && squareStk . top ( ) == ' [ ' ) { squareStk . pop ( ) ; squareCount += 1 ; } } else if ( s [ i ] == ' ( ' ) { roundStk . push ( s [ i ] ) ; } else { if ( roundStk . size ( ) != 0 && squareStk . top ( ) == ' ( ' ) { squareStk . pop ( ) ; roundCount += 1 ; } } } cout << ( N - ( 2 * squareCount + 2 * roundCount ) ) ; } int main ( ) { string s = " [ ] ] ) ( [ " ; deleteSubseq ( s ) ; }

Index/key variables: i
Accumulator variables: i, roundCount, squareCount, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minimumOperations ( string s , int n ) { unordered_map < char , vector < int > > mp ; for ( int i = 0 ; i < n ; i ++ ) { mp [ s [ i ] ] . push_back ( i ) ; } int ans = INT_MAX ; for ( auto x : mp ) { int curr = 0 ; int prev = 0 ; bool first = true ; for ( int index : ( x . second ) ) { if ( first ) { if ( index > 0 ) { curr ++ ; } prev = index ; first = false ; } else { if ( index != prev + 1 ) { curr ++ ; } prev = index ; } } if ( prev != n - 1 ) { curr ++ ; } ans = min ( ans , curr ) ; } cout << ans ; } int main ( ) { string s = " YYXYZYXYZXY " ; int N = s . length ( ) ; minimumOperations ( s , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: curr, i, stdc
Iterator variables: i, index, x
Boolean variables: first
C++ program:
#include <bits/stdc++.h>
using namespace std ; void checkValidDFA ( string s ) { int initial_state = 0 ; int final_state ; int previous_state = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( ( s [ i ] == '0' && previous_state == 0 ) || ( s [ i ] == '1' && previous_state == 3 ) ) { final_state = 1 ; } else if ( ( s [ i ] == '0' && previous_state == 3 ) || ( s [ i ] == '1' && previous_state == 0 ) ) { final_state = 2 ; } else if ( ( s [ i ] == '0' && previous_state == 1 ) || ( s [ i ] == '1' && previous_state == 2 ) ) { final_state = 0 ; } else if ( ( s [ i ] == '0' && previous_state == 2 ) || ( s [ i ] == '1' && previous_state == 1 ) ) { final_state = 3 ; } previous_state = final_state ; } if ( final_state == 3 ) { cout << " Accepted " << endl ; } else { cout << " Not ▁ Accepted " << endl ; } } int main ( ) { string s = "010011" ; checkValidDFA ( s ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; Node * left , * right ; } ; Node * newNode ( int data ) { Node * temp = new Node ( ) ; temp -> data = data ; temp -> left = temp -> right = NULL ; return temp ; } int evenOddLevelDifference ( Node * root ) { if ( ! root ) return 0 ; queue < Node * > q ; q . push ( root ) ; int level = 0 ; int evenSum = 0 , oddSum = 0 ; while ( ! q . empty ( ) ) { int size = q . size ( ) ; level += 1 ; while ( size > 0 ) { Node * temp = q . front ( ) ; q . pop ( ) ; if ( level % 2 == 0 ) evenSum += temp -> data ; else oddSum += temp -> data ; if ( temp -> left ) { q . push ( temp -> left ) ; } if ( temp -> right ) { q . push ( temp -> right ) ; } size -= 1 ; } } return ( oddSum - evenSum ) ; } int main ( ) { Node * root = newNode ( 5 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 6 ) ; root -> left -> left = newNode ( 1 ) ; root -> left -> right = newNode ( 4 ) ; root -> left -> right -> left = newNode ( 3 ) ; root -> right -> right = newNode ( 8 ) ; root -> right -> right -> right = newNode ( 9 ) ; root -> right -> right -> left = newNode ( 7 ) ; int result = evenOddLevelDifference ( root ) ; cout << " diffence ▁ between ▁ sums ▁ is ▁ : : ▁ " ; cout << result << endl ; return 0 ; }

Accumulator variables: evenSum, level, oddSum, size, stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; class node { public : int data ; node * left , * right ; } ; node * newNode ( int data ) { node * Node = new node ( ) ; Node -> data = data ; Node -> left = Node -> right = NULL ; return ( Node ) ; } int getLevelDiff ( node * root ) { if ( root == NULL ) return 0 ; return root -> data - getLevelDiff ( root -> left ) - getLevelDiff ( root -> right ) ; } int main ( ) { node * root = newNode ( 5 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 6 ) ; root -> left -> left = newNode ( 1 ) ; root -> left -> right = newNode ( 4 ) ; root -> left -> right -> left = newNode ( 3 ) ; root -> right -> right = newNode ( 8 ) ; root -> right -> right -> right = newNode ( 9 ) ; root -> right -> right -> left = newNode ( 7 ) ; cout << getLevelDiff ( root ) << " ▁ is ▁ the ▁ required ▁ difference STRNEWLINE " ; 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 data ) { Node * node = new Node ; node -> data = data ; node -> left = node -> right = NULL ; return node ; } int maxSum ( vector < int > arr , int n ) { int max_ending_here = INT_MIN ; int max_so_far = INT_MIN ; for ( int i = 0 ; i < n ; i ++ ) { if ( max_ending_here < 0 ) max_ending_here = arr [ i ] ; else max_ending_here += arr [ i ] ; max_so_far = max ( max_so_far , max_ending_here ) ; } return max_so_far ; } int maxSpiralSum ( Node * root ) { if ( root == NULL ) return 0 ; stack < Node * > s1 ; stack < Node * > s2 ; vector < int > arr ; s1 . push ( root ) ; while ( ! s1 . empty ( ) || ! s2 . empty ( ) ) { while ( ! s1 . empty ( ) ) { Node * temp = s1 . top ( ) ; s1 . pop ( ) ; arr . push_back ( temp -> data ) ; if ( temp -> right ) s2 . push ( temp -> right ) ; if ( temp -> left ) s2 . push ( temp -> left ) ; } while ( ! s2 . empty ( ) ) { Node * temp = s2 . top ( ) ; s2 . pop ( ) ; arr . push_back ( temp -> data ) ; if ( temp -> left ) s1 . push ( temp -> left ) ; if ( temp -> right ) s1 . push ( temp -> right ) ; } } return maxSum ( arr , arr . size ( ) ) ; } int main ( ) { Node * root = newNode ( -2 ) ; root -> left = newNode ( -3 ) ; root -> right = newNode ( 4 ) ; root -> left -> left = newNode ( 5 ) ; root -> left -> right = newNode ( 1 ) ; root -> right -> left = newNode ( -2 ) ; root -> right -> right = newNode ( -1 ) ; root -> left -> left -> left = newNode ( -3 ) ; root -> right -> right -> right = newNode ( 2 ) ; cout << " Maximum ▁ Spiral ▁ Sum ▁ = ▁ " << maxSpiralSum ( root ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, max_ending_here, stdc
Iterator variables: i
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; Node * left , * right ; } ; Node * newNode ( int data ) { Node * temp = new Node ( ) ; temp -> data = data ; temp -> left = temp -> right = NULL ; return temp ; } void leafSum ( Node * root , int & sum ) { if ( ! root ) return ; if ( ! root -> left && ! root -> right ) sum += root -> data ; leafSum ( root -> left , sum ) ; leafSum ( root -> right , sum ) ; } int main ( ) { Node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 5 ) ; root -> right = newNode ( 3 ) ; root -> right -> right = newNode ( 7 ) ; root -> right -> left = newNode ( 6 ) ; root -> right -> left -> right = newNode ( 8 ) ; int sum = 0 ; leafSum ( root , sum ) ; cout << sum << endl ; return 0 ; }

Accumulator variables: stdc, sum
Class/struct names: Node
C++ program:
#include <stdio.h>
#include <stdlib.h>
struct tNode { int data ; struct tNode * left ; struct tNode * right ; } ; void MorrisTraversal ( struct tNode * root ) { struct tNode * current , * pre ; if ( root == NULL ) return ; current = root ; while ( current != NULL ) { if ( current -> left == NULL ) { printf ( " % d ▁ " , current -> data ) ; current = current -> right ; } else { pre = current -> left ; while ( pre -> right != NULL && pre -> right != current ) pre = pre -> right ; if ( pre -> right == NULL ) { pre -> right = current ; current = current -> left ; } else { pre -> right = NULL ; printf ( " % d ▁ " , current -> data ) ; current = current -> right ; } } } } struct tNode * newtNode ( int data ) { struct tNode * node = new tNode ; node -> data = data ; node -> left = NULL ; node -> right = NULL ; return ( node ) ; } int main ( ) { struct tNode * root = newtNode ( 1 ) ; root -> left = newtNode ( 2 ) ; root -> right = newtNode ( 3 ) ; root -> left -> left = newtNode ( 4 ) ; root -> left -> right = newtNode ( 5 ) ; MorrisTraversal ( root ) ; return 0 ; }

Class/struct names: tNode
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; Node * left , * right ; } ; Node * getNode ( int data ) { Node * newNode = ( Node * ) malloc ( sizeof ( Node ) ) ; newNode -> data = data ; newNode -> left = newNode -> right = NULL ; return newNode ; } int sumOfLeafNodesAtMinLevel ( Node * root ) { if ( ! root ) return 0 ; if ( ! root -> left && ! root -> right ) return root -> data ; queue < Node * > q ; int sum = 0 ; bool f = 0 ; q . push ( root ) ; while ( f == 0 ) { int nc = q . size ( ) ; while ( nc -- ) { Node * top = q . front ( ) ; q . pop ( ) ; if ( ! top -> left && ! top -> right ) { sum += top -> data ; f = 1 ; } else { if ( top -> left ) q . push ( top -> left ) ; if ( top -> right ) q . push ( top -> right ) ; } } } return sum ; } int main ( ) { Node * root = getNode ( 1 ) ; root -> left = getNode ( 2 ) ; root -> right = getNode ( 3 ) ; root -> left -> left = getNode ( 4 ) ; root -> left -> right = getNode ( 5 ) ; root -> right -> left = getNode ( 6 ) ; root -> right -> right = getNode ( 7 ) ; root -> left -> right -> left = getNode ( 8 ) ; root -> right -> left -> right = getNode ( 9 ) ; cout << " Sum ▁ = ▁ " << sumOfLeafNodesAtMinLevel ( root ) ; return 0 ; }

Accumulator variables: nc, stdc, sum
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define bool  int
class node { public : int data ; node * left ; node * right ; } ; bool hasPathSum ( node * Node , int sum ) { if ( Node == NULL ) { return ( sum == 0 ) ; } else { bool ans = 0 ; int subSum = sum - Node -> data ; if ( subSum == 0 && Node -> left == NULL && Node -> right == NULL ) return 1 ; if ( Node -> left ) ans = ans || hasPathSum ( Node -> left , subSum ) ; if ( Node -> right ) ans = ans || hasPathSum ( Node -> right , subSum ) ; return ans ; } } node * newnode ( int data ) { node * Node = new node ( ) ; Node -> data = data ; Node -> left = NULL ; Node -> right = NULL ; return ( Node ) ; } int main ( ) { int sum = 21 ; node * root = newnode ( 10 ) ; root -> left = newnode ( 8 ) ; root -> right = newnode ( 2 ) ; root -> left -> left = newnode ( 3 ) ; root -> left -> right = newnode ( 5 ) ; root -> right -> left = newnode ( 2 ) ; if ( hasPathSum ( root , sum ) ) cout << " There ▁ is ▁ a ▁ root - to - leaf ▁ path ▁ with ▁ sum ▁ " << sum ; else cout << " There ▁ is ▁ no ▁ root - to - leaf ▁ path ▁ with ▁ sum ▁ " << sum ; return 0 ; }

Accumulator variables: stdc
Class/struct names: node
C++ program:
#include <bits/stdc++.h>
using namespace std ; class node { public : int data ; node * left , * right ; } ; node * newNode ( int data ) { node * Node = new node ( ) ; Node -> data = data ; Node -> left = Node -> right = NULL ; return ( Node ) ; } int treePathsSumUtil ( node * root , int val ) { if ( root == NULL ) return 0 ; val = ( val * 10 + root -> data ) ; if ( root -> left == NULL && root -> right == NULL ) return val ; return treePathsSumUtil ( root -> left , val ) + treePathsSumUtil ( root -> right , val ) ; } int treePathsSum ( node * root ) { return treePathsSumUtil ( root , 0 ) ; } int main ( ) { node * root = newNode ( 6 ) ; root -> left = newNode ( 3 ) ; root -> right = newNode ( 5 ) ; root -> left -> left = newNode ( 2 ) ; root -> left -> right = newNode ( 5 ) ; root -> right -> right = newNode ( 4 ) ; root -> left -> right -> left = newNode ( 7 ) ; root -> left -> right -> right = newNode ( 4 ) ; cout << " Sum ▁ of ▁ all ▁ paths ▁ is ▁ " << treePathsSum ( root ) ; 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 , * right ; } ; Node * newNode ( int data ) { Node * new_node = new Node ; new_node -> data = data ; new_node -> left = new_node -> right = NULL ; return new_node ; } void inorder ( Node * node ) { if ( ! node ) return ; inorder ( node -> left ) ; printf ( " % d ▁ " , node -> data ) ; inorder ( node -> right ) ; } Node * MergeTrees ( Node * t1 , Node * t2 ) { if ( ! t1 ) return t2 ; if ( ! t2 ) return t1 ; t1 -> data += t2 -> data ; t1 -> left = MergeTrees ( t1 -> left , t2 -> left ) ; t1 -> right = MergeTrees ( t1 -> right , t2 -> right ) ; return t1 ; } int main ( ) { Node * root1 = newNode ( 1 ) ; root1 -> left = newNode ( 2 ) ; root1 -> right = newNode ( 3 ) ; root1 -> left -> left = newNode ( 4 ) ; root1 -> left -> right = newNode ( 5 ) ; root1 -> right -> right = newNode ( 6 ) ; Node * root2 = newNode ( 4 ) ; root2 -> left = newNode ( 1 ) ; root2 -> right = newNode ( 7 ) ; root2 -> left -> left = newNode ( 3 ) ; root2 -> right -> left = newNode ( 2 ) ; root2 -> right -> right = newNode ( 6 ) ; Node * root3 = MergeTrees ( root1 , root2 ) ; printf ( " The ▁ Merged ▁ Binary ▁ Tree ▁ is : STRNEWLINE " ) ; inorder ( root3 ) ; return 0 ; }

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