dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int subzero ( string str , int k ) { int ans = 0 , curr = 0 ; int len = str . length ( ) ; for ( int i = 0 ; i < len ; ++ i ) { if ( str [ i ] == '0' ) curr ++ ; else curr = 0 ; ans = max ( ans , curr ) ; } if ( ans == len ) return len * k ; else { int pre = 0 , suff = 0 ; for ( int i = 0 ; i < len ; i ++ ) { if ( str [ i ] == '0' ) pre ++ ; else break ; } for ( int i = len - 1 ; i >= 0 ; i -- ) { if ( str [ i ] == '0' ) suff ++ ; else break ; } if ( k > 1 ) ans = max ( ans , pre + suff ) ; return ans ; } } int main ( ) { string str = "00100110" ; int k = 5 ; cout << subzero ( str , k ) ; return 0 ; }

Index/key variables: i
Accumulator variables: curr, i, pre, stdc, suff
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string Dragon_Curve_Sequence ( int n ) { string s = "1" ; for ( int i = 2 ; i <= n ; i ++ ) { string temp = "1" ; char prev = '1' , zero = '0' , one = '1' ; for ( int j = 0 ; j < s . length ( ) ; j ++ ) { temp += s [ j ] ; if ( prev == '0' ) { temp += one ; prev = one ; } else { temp += zero ; prev = zero ; } } s = temp ; } return s ; } int main ( ) { int n = 4 ; string s = Dragon_Curve_Sequence ( n ) ; cout << s << " STRNEWLINE " ; }

Index/key variables: j
Accumulator variables: i, j, stdc, temp
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countNonEmptySubstr ( string str ) { int n = str . length ( ) ; return n * ( n + 1 ) / 2 ; } int main ( ) { string s = " abcde " ; cout << countNonEmptySubstr ( s ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findSubstrings ( string s , int k ) { int ans = 0 ; int cnt [ 26 ] ; int i , j , n = s . length ( ) ; for ( i = 0 ; i < n ; i ++ ) { memset ( cnt , 0 , sizeof ( cnt ) ) ; for ( j = i ; j < n ; j ++ ) { cnt [ s [ j ] - ' a ' ] ++ ; if ( cnt [ s [ j ] - ' a ' ] <= k ) ans ++ ; else break ; } } return ans ; } int main ( ) { string S = " aaabb " ; int k = 2 ; cout << findSubstrings ( S , k ) ; return 0 ; }

Index/key variables: j
Accumulator variables: ans, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MAX = 26 ; bool targetstring ( string str1 , string str2 ) { int l1 = str1 . length ( ) ; int l2 = str2 . length ( ) ; if ( l1 != l2 ) return false ; int map [ MAX ] = { 0 } ; for ( int i = 0 ; i < l1 ; i ++ ) map [ str1 [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < l2 ; i ++ ) { map [ str2 [ i ] - ' a ' ] -- ; if ( map [ str2 [ i ] - ' a ' ] < 0 ) return false ; } return true ; } int main ( ) { string str1 = " geeksforgeeks " ; string str2 = " geegeeksksfor " ; if ( targetstring ( str1 , str2 ) ) cout << " YES " ; else cout << " NO " ; return 0 ; }

Index/key variables: MAX, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isDigitPresent ( int x , int d ) { while ( x > 0 ) { if ( x % 10 == d ) break ; x = x / 10 ; } return ( x > 0 ) ; } void printNumbers ( int n , int d ) { for ( int i = 0 ; i <= n ; i ++ ) if ( i == d || isDigitPresent ( i , d ) ) cout << i << " ▁ " ; } int main ( ) { int n = 47 , d = 7 ; printNumbers ( n , d ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; char findExtraCharcter ( string strA , string strB ) { unordered_map < char , int > m1 ; for ( int i = 0 ; i < strB . length ( ) ; i ++ ) m1 [ strB [ i ] ] ++ ; for ( int i = 0 ; i < strA . length ( ) ; i ++ ) m1 [ strA [ i ] ] -- ; for ( auto h1 = m1 . begin ( ) ; h1 != m1 . end ( ) ; h1 ++ ) { if ( h1 -> second == 1 ) return h1 -> first ; } } int main ( ) { string strA = " abcd " ; string strB = " cbdad " ; cout << findExtraCharcter ( strA , strB ) ; }

Index/key variables: i
Accumulator variables: h1, i, stdc
Iterator variables: h1, i
C++ program:
#include <iostream>
using namespace std ; char findExtraCharcter ( string strA , string strB ) { int res = 0 , i ; for ( i = 0 ; i < strA . length ( ) ; i ++ ) { res ^= strA [ i ] ; } for ( i = 0 ; i < strB . length ( ) ; i ++ ) { res ^= strB [ i ] ; } return ( ( char ) ( res ) ) ; } int main ( ) { string strA = " abcd " ; string strB = " cbdad " ; cout << findExtraCharcter ( strA , strB ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, res
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; char findExtraCharacter ( string s1 , string s2 ) { string smallStr ; string largeStr ; if ( s1 . size ( ) > s2 . size ( ) ) { smallStr = s2 ; largeStr = s1 ; } else { smallStr = s1 ; largeStr = s2 ; } int smallStrCodeTotal = 0 ; int largeStrCodeTotal = 0 ; int i = 0 ; for ( ; i < smallStr . size ( ) ; i ++ ) { smallStrCodeTotal += smallStr [ i ] ; largeStrCodeTotal += largeStr [ i ] ; } largeStrCodeTotal += largeStr [ i ] ; int intChar = largeStrCodeTotal - smallStrCodeTotal ; return ( char ) intChar ; } int main ( ) { string s1 = " abcd " ; string s2 = " cbdae " ; char extraChar = findExtraCharacter ( s1 , s2 ) ; cout << " Extra ▁ character : ▁ " << ( extraChar ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, largeStrCodeTotal, smallStrCodeTotal, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void myCopy ( char s1 [ ] , char s2 [ ] ) { int i = 0 ; for ( i = 0 ; s1 [ i ] != ' \0' ; i ++ ) s2 [ i ] = s1 [ i ] ; s2 [ i ] = ' \0' ; } int main ( ) { char s1 [ 100 ] = " GEEKSFORGEEKS " ; char s2 [ 100 ] = " " ; myCopy ( s1 , s2 ) ; cout << s2 ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int calculateSum ( string arr [ ] , int n ) { if ( n == 0 ) return 0 ; string s = arr [ 0 ] ; int value = stoi ( s ) ; int sum = value ; for ( int i = 2 ; i < n ; i = i + 2 ) { s = arr [ i ] ; int value = stoi ( s ) ; char operation = arr [ i - 1 ] [ 0 ] ; if ( operation == ' + ' ) sum += value ; else sum -= value ; } return sum ; } int main ( ) { string arr [ ] = { "3" , " + " , "4" , " - " , "7" , " + " , "13" } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << calculateSum ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MAX_CHAR = 26 ; bool twoStrings ( string s1 , string s2 ) { vector < bool > v ( MAX_CHAR , 0 ) ; for ( int i = 0 ; i < s1 . length ( ) ; i ++ ) v [ s1 [ i ] - ' a ' ] = true ; for ( int i = 0 ; i < s2 . length ( ) ; i ++ ) if ( v [ s2 [ i ] - ' a ' ] ) return true ; return false ; } int main ( ) { string str1 = " hello " ; string str2 = " world " ; if ( twoStrings ( str1 , str2 ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void LargestString ( string * na ) { int N = sizeof ( na ) / sizeof ( na [ 0 ] ) ; int c [ N ] ; int m = 1 ; for ( int j = 0 ; j < N ; j ++ ) { bool character [ 26 ] ; for ( int k = 0 ; k < na [ j ] . size ( ) ; k ++ ) { int x = ( int ) ( na [ j ] [ k ] - ' A ' ) ; if ( na [ j ] [ k ] != ' ▁ ' && character [ x ] == false ) { c [ j ] ++ ; character [ x ] = true ; } } if ( c [ j ] > c [ m ] ) m = j ; } cout << na [ m ] << endl ; } int main ( ) { string na [ ] = { " BOB " , " A ▁ AB ▁ C ▁ JOHNSON " , " ANJALI " , " ASKRIT " , " ARMAN ▁ MALLIK " } ; LargestString ( na ) ; }

Index/key variables: N, j, k, m, x
Accumulator variables: j, k, stdc
Iterator variables: j, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; int LongestWordLength ( string str ) { int counter = 0 ; string words [ 100 ] ; for ( short i = 0 ; i < str . length ( ) ; i ++ ) { if ( str [ i ] == ' ▁ ' ) counter ++ ; else words [ counter ] += str [ i ] ; } int length = 0 ; for ( string word : words ) { if ( length < word . length ( ) ) { length = word . length ( ) ; } } return length ; } int main ( ) { string str = " I ▁ am ▁ an ▁ intern ▁ at ▁ geeksforgeeks " ; cout << ( LongestWordLength ( str ) ) ; }

Index/key variables: counter, i
Accumulator variables: counter, i, stdc
Iterator variables: i, word
C++ program:
#include <iostream>
using namespace std ; string morseEncode ( char x ) { switch ( x ) { case ' a ' : return " . - " ; case ' b ' : return " - . . . " ; case ' c ' : return " - . - . " ; case ' d ' : return " - . . " ; case ' e ' : return " . " ; case ' f ' : return " . . - . " ; case ' g ' : return " - - . " ; case ' h ' : return " . . . . " ; case ' i ' : return " . . " ; case ' j ' : return " . - - - " ; case ' k ' : return " - . - " ; case ' l ' : return " . - . . " ; case ' m ' : return " - - " ; case ' n ' : return " - . " ; case ' o ' : return " - - - " ; case ' p ' : return " . - - . " ; case ' q ' : return " - - . - " ; case ' r ' : return " . - . " ; case ' s ' : return " . . . " ; case ' t ' : return " - " ; case ' u ' : return " . . - " ; case ' v ' : return " . . . - " ; case ' w ' : return " . - - " ; case ' x ' : return " - . . - " ; case ' y ' : return " - . - - " ; case ' z ' : return " - - . . " ; case '1' : return " . - - - - " ; case '2' : return " . . - - - " ; case '3' : return " . . . - - " ; case '4' : return " . . . . - " ; case '5' : return " . . . . . " ; case '6' : return " - . . . . " ; case '7' : return " - - . . . " ; case '8' : return " - - - . . " ; case '9' : return " - - - - . " ; case '0' : return " - - - - - " ; default : cerr << " Found ▁ invalid ▁ character : ▁ " << x << ' ▁ ' << std :: endl ; exit ( 0 ) ; } } void morseCode ( string s ) { for ( int i = 0 ; s [ i ] ; i ++ ) cout << morseEncode ( s [ i ] ) ; cout << endl ; } int main ( ) { string s = " geeksforgeeks " ; morseCode ( s ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <cmath>
#include <iostream>
using namespace std ; void polybiusCipher ( string s ) { int row , col ; for ( int i = 0 ; s [ i ] ; i ++ ) { row = ceil ( ( s [ i ] - ' a ' ) / 5 ) + 1 ; col = ( ( s [ i ] - ' a ' ) % 5 ) + 1 ; if ( s [ i ] == ' k ' ) { row = row - 1 ; col = 5 - col + 1 ; } else if ( s [ i ] >= ' j ' ) { if ( col == 1 ) { col = 6 ; row = row - 1 ; } col = col - 1 ; } cout << row << col ; } cout << endl ; } int main ( ) { string s = " geeksforgeeks " ; polybiusCipher ( s ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; #define MAX_CHAR  26
int minRemoval ( string str ) { int hash [ MAX_CHAR ] ; memset ( hash , 0 , sizeof ( hash ) ) ; for ( int i = 0 ; str [ i ] ; i ++ ) hash [ str [ i ] - ' a ' ] ++ ; int count = 0 ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) if ( hash [ i ] % 2 ) count ++ ; return ( count == 0 ) ? 0 : count - 1 ; } int main ( ) { string str = " geeksforgeeks " ; cout << minRemoval ( str ) << endl ; return 0 ; }

Index/key variables: MAX_CHAR, i
Accumulator variables: count, i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MAX_VERTEX = 101 ; int Arr [ MAX_VERTEX ] ; int size [ MAX_VERTEX ] ; void initialize ( int n ) { for ( int i = 0 ; i <= n ; i ++ ) { Arr [ i ] = i ; size [ i ] = 1 ; } } int find ( int i ) { while ( Arr [ i ] != i ) { Arr [ i ] = Arr [ Arr [ i ] ] ; i = Arr [ i ] ; } return i ; } void _union ( int xr , int yr ) { if ( size [ xr ] < size [ yr ] ) { Arr [ xr ] = Arr [ yr ] ; size [ yr ] += size [ xr ] ; } else { Arr [ yr ] = Arr [ xr ] ; size [ xr ] += size [ yr ] ; } } int isCycle ( vector < int > adj [ ] , int V ) { for ( int i = 0 ; i < V ; i ++ ) { for ( int j = 0 ; j < adj [ i ] . size ( ) ; j ++ ) { int x = find ( i ) ; int y = find ( adj [ i ] [ j ] ) ; if ( x == y ) return 1 ; _union ( x , y ) ; } } return 0 ; } int main ( ) { int V = 3 ; initialize ( V ) ; vector < int > adj [ V ] ; adj [ 0 ] . push_back ( 1 ) ; adj [ 0 ] . push_back ( 2 ) ; adj [ 1 ] . push_back ( 2 ) ; if ( isCycle ( adj , V ) ) cout << " Gxrph ▁ contains ▁ Cycle . STRNEWLINE " ; else cout << " Gxrph ▁ does ▁ not ▁ contain ▁ Cycle . STRNEWLINE " ; return 0 ; }

Index/key variables: MAX_VERTEX, V, i, j, xr, yr
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
#define MAX_LEN  1005
#define MAX_CHAR  26
using namespace std ; int cnt [ MAX_LEN ] [ MAX_CHAR ] ; void preProcess ( string s ) { int n = s . length ( ) ; memset ( cnt , 0 , sizeof ( cnt ) ) ; for ( int i = 0 ; i < n ; i ++ ) cnt [ i ] [ s [ i ] - ' a ' ] ++ ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j < 26 ; j ++ ) cnt [ i ] [ j ] += cnt [ i - 1 ] [ j ] ; } } int findCharFreq ( int l , int r , char c ) { int count = cnt [ r ] [ c - ' a ' ] ; if ( l != 0 ) count -= cnt [ l - 1 ] [ c - ' a ' ] ; return count ; } int main ( ) { string s = " geeksforgeeks " ; int Q = 4 ; preProcess ( s ) ; cout << findCharFreq ( 0 , 5 , ' e ' ) << endl ; cout << findCharFreq ( 2 , 6 , ' f ' ) << endl ; cout << findCharFreq ( 4 , 7 , ' m ' ) << endl ; cout << findCharFreq ( 0 , 12 , ' e ' ) << endl ; return 0 ; }

Index/key variables: MAX_CHAR, MAX_LEN, i, j, r
Accumulator variables: count, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void swapTwoHalves ( string a , string b ) { int la = a . length ( ) ; int lb = b . length ( ) ; string c = a . substr ( 0 , la / 2 ) + b . substr ( lb / 2 , lb ) ; string d = b . substr ( 0 , lb / 2 ) + a . substr ( la / 2 , la ) ; cout << c << endl << d << endl ; } int main ( ) { string a = " remuneration " ; string b = " day " ; swapTwoHalves ( a , b ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void solve ( string a , string b , int k ) { string s = " " ; int la = a . length ( ) ; int lb = b . length ( ) ; int l = la + lb ; int indexa = 0 , indexb = 0 ; while ( l > 0 ) { int pa = 0 , pb = 0 ; if ( la - indexa >= k ) { s = s + a . substr ( indexa , k ) ; indexa = indexa + k ; pa = k ; } else if ( la - indexa < k && la - indexa > 0 ) { s = s + a . substr ( indexa , la - indexa ) ; pa = la - indexa ; indexa = la ; } else if ( indexa >= la ) pa = 0 ; if ( lb - indexb >= k ) { s = s + b . substr ( indexb , k ) ; pb = k ; indexb = indexb + k ; } else if ( lb - indexb < k && lb - indexb > 0 ) { s = s + b . substr ( indexb , lb - indexb ) ; pb = lb - indexb ; indexb = lb ; } else if ( indexb >= lb ) pb = 0 ; l = l - pa - pb ; } cout << s ; } int main ( ) { string a = " determination " , b = " stance " ; int k = 3 ; solve ( a , b , k ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void DFS ( vector < pair < int , int > > graph [ ] , int src , int prev_len , int * max_len , vector < bool > & visited ) { visited [ src ] = 1 ; int curr_len = 0 ; pair < int , int > adjacent ; for ( int i = 0 ; i < graph [ src ] . size ( ) ; i ++ ) { adjacent = graph [ src ] [ i ] ; if ( ! visited [ adjacent . first ] ) { curr_len = prev_len + adjacent . second ; DFS ( graph , adjacent . first , curr_len , max_len , visited ) ; } if ( ( * max_len ) < curr_len ) * max_len = curr_len ; curr_len = 0 ; } } int longestCable ( vector < pair < int , int > > graph [ ] , int n ) { int max_len = INT_MIN ; for ( int i = 1 ; i <= n ; i ++ ) { vector < bool > visited ( n + 1 , false ) ; DFS ( graph , i , 0 , & max_len , visited ) ; } return max_len ; } int main ( ) { int n = 6 ; vector < pair < int , int > > graph [ n + 1 ] ; graph [ 1 ] . push_back ( make_pair ( 2 , 3 ) ) ; graph [ 2 ] . push_back ( make_pair ( 1 , 3 ) ) ; graph [ 2 ] . push_back ( make_pair ( 3 , 4 ) ) ; graph [ 3 ] . push_back ( make_pair ( 2 , 4 ) ) ; graph [ 2 ] . push_back ( make_pair ( 6 , 2 ) ) ; graph [ 6 ] . push_back ( make_pair ( 2 , 2 ) ) ; graph [ 4 ] . push_back ( make_pair ( 6 , 6 ) ) ; graph [ 6 ] . push_back ( make_pair ( 4 , 6 ) ) ; graph [ 5 ] . push_back ( make_pair ( 6 , 5 ) ) ; graph [ 6 ] . push_back ( make_pair ( 5 , 5 ) ) ; cout << " Maximum ▁ length ▁ of ▁ cable ▁ = ▁ " << longestCable ( graph , n ) ; return 0 ; }

Index/key variables: i, src
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <iostream>
#include <queue>
#include <stack>
using namespace std ; struct Node { struct Node * left ; int data ; struct Node * right ; } ; void modifiedLevelOrder ( struct Node * node ) { if ( node == NULL ) return ; if ( node -> left == NULL && node -> right == NULL ) { cout << node -> data ; return ; } queue < Node * > myQueue ; stack < Node * > myStack ; struct Node * temp = NULL ; int sz ; int ct = 0 ; bool rightToLeft = false ; myQueue . push ( node ) ; while ( ! myQueue . empty ( ) ) { ct ++ ; sz = myQueue . size ( ) ; for ( int i = 0 ; i < sz ; i ++ ) { temp = myQueue . front ( ) ; myQueue . pop ( ) ; if ( rightToLeft == false ) cout << temp -> data << " ▁ " ; else myStack . push ( temp ) ; if ( temp -> left ) myQueue . push ( temp -> left ) ; if ( temp -> right ) myQueue . push ( temp -> right ) ; } if ( rightToLeft == true ) { while ( ! myStack . empty ( ) ) { temp = myStack . top ( ) ; myStack . pop ( ) ; cout << temp -> data << " ▁ " ; } } if ( ct == 2 ) { rightToLeft = ! rightToLeft ; ct = 0 ; } cout << " STRNEWLINE " ; } } Node * newNode ( int data ) { Node * temp = new Node ; temp -> data = data ; temp -> left = temp -> right = NULL ; return temp ; } 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 -> 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 ( 3 ) ; root -> left -> right -> right = newNode ( 1 ) ; root -> right -> left -> left = newNode ( 4 ) ; root -> right -> left -> right = newNode ( 2 ) ; root -> right -> right -> left = newNode ( 7 ) ; root -> right -> right -> right = newNode ( 2 ) ; root -> left -> right -> left -> left = newNode ( 16 ) ; root -> left -> right -> left -> right = newNode ( 17 ) ; root -> right -> left -> right -> left = newNode ( 18 ) ; root -> right -> right -> left -> right = newNode ( 19 ) ; modifiedLevelOrder ( root ) ; return 0 ; }

Accumulator variables: ct, i
Iterator variables: i
Boolean variables: rightToLeft
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minnode ( int n , int keyval [ ] , bool mstset [ ] ) { int mini = numeric_limits < int > :: max ( ) ; int mini_index ; for ( int i = 0 ; i < n ; i ++ ) { if ( mstset [ i ] == false && keyval [ i ] < mini ) { mini = keyval [ i ] , mini_index = i ; } } return mini_index ; } void findcost ( int n , vector < vector < int > > city ) { int parent [ n ] ; int keyval [ n ] ; bool mstset [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { keyval [ i ] = numeric_limits < int > :: max ( ) ; mstset [ i ] = false ; } parent [ 0 ] = -1 ; keyval [ 0 ] = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { int u = minnode ( n , keyval , mstset ) ; mstset [ u ] = true ; for ( int v = 0 ; v < n ; v ++ ) { if ( city [ u ] [ v ] && mstset [ v ] == false && city [ u ] [ v ] < keyval [ v ] ) { keyval [ v ] = city [ u ] [ v ] ; parent [ v ] = u ; } } } int cost = 0 ; for ( int i = 1 ; i < n ; i ++ ) cost += city [ parent [ i ] ] [ i ] ; cout << cost << endl ; } int main ( ) { int n1 = 5 ; vector < vector < int > > city1 = { { 0 , 1 , 2 , 3 , 4 } , { 1 , 0 , 5 , 0 , 7 } , { 2 , 5 , 0 , 6 , 0 } , { 3 , 0 , 6 , 0 , 0 } , { 4 , 7 , 0 , 0 , 0 } } ; findcost ( n1 , city1 ) ; int n2 = 6 ; vector < vector < int > > city2 = { { 0 , 1 , 1 , 100 , 0 , 0 } , { 1 , 0 , 1 , 0 , 0 , 0 } , { 1 , 1 , 0 , 0 , 0 , 0 } , { 100 , 0 , 0 , 0 , 2 , 2 } , { 0 , 0 , 0 , 2 , 0 , 2 } , { 0 , 0 , 0 , 2 , 2 , 0 } } ; findcost ( n2 , city2 ) ; return 0 ; }

Index/key variables: i, n, u, v
Accumulator variables: cost, i, stdc, v
Iterator variables: i, v
C++ program:
#include <bits/stdc++.h>
#define V  5
int minKey ( int key [ ] , bool mstSet [ ] ) { int min = INT_MAX , min_index ; for ( int v = 0 ; v < V ; v ++ ) if ( mstSet [ v ] == false && key [ v ] < min ) min = key [ v ] , min_index = v ; return min_index ; } int printMST ( int parent [ ] , int n , int graph [ V ] [ V ] ) { printf ( " Edge ▁ Weight STRNEWLINE " ) ; int minProduct = 1 ; for ( int i = 1 ; i < V ; i ++ ) { printf ( " % d ▁ - ▁ % d ▁ % d ▁ STRNEWLINE " , parent [ i ] , i , graph [ i ] [ parent [ i ] ] ) ; minProduct *= graph [ i ] [ parent [ i ] ] ; } printf ( " Minimum ▁ Obtainable ▁ product ▁ is ▁ % d STRNEWLINE " , minProduct ) ; } void primMST ( int inputGraph [ V ] [ V ] , double logGraph [ V ] [ V ] ) { int parent [ V ] ; int key [ V ] ; bool mstSet [ V ] ; for ( int i = 0 ; i < V ; i ++ ) key [ i ] = INT_MAX , mstSet [ i ] = false ; key [ 0 ] = 0 ; parent [ 0 ] = -1 ; for ( int count = 0 ; count < V - 1 ; count ++ ) { int u = minKey ( key , mstSet ) ; mstSet [ u ] = true ; for ( int v = 0 ; v < V ; v ++ ) if ( logGraph [ u ] [ v ] > 0 && mstSet [ v ] == false && logGraph [ u ] [ v ] < key [ v ] ) parent [ v ] = u , key [ v ] = logGraph [ u ] [ v ] ; } printMST ( parent , V , inputGraph ) ; } void minimumProductMST ( int graph [ V ] [ V ] ) { double logGraph [ V ] [ V ] ; for ( int i = 0 ; i < V ; i ++ ) { for ( int j = 0 ; j < V ; j ++ ) { if ( graph [ i ] [ j ] > 0 ) logGraph [ i ] [ j ] = log ( graph [ i ] [ j ] ) ; else logGraph [ i ] [ j ] = 0 ; } } primMST ( graph , logGraph ) ; } int main ( ) { int graph [ V ] [ V ] = { { 0 , 2 , 0 , 6 , 0 } , { 2 , 0 , 3 , 8 , 5 } , { 0 , 3 , 0 , 0 , 7 } , { 6 , 8 , 0 , 0 , 9 } , { 0 , 5 , 7 , 9 , 0 } , } ; minimumProductMST ( graph ) ; return 0 ; }

Index/key variables: V, i, j, u, v
Accumulator variables: count, i, j, minProduct, stdc, v
Iterator variables: count, i, j, v
C++ program:
#include <iostream>
#include <stack>
#include <queue>
using namespace std ; #define LEFT  0
#define RIGHT  1
#define ChangeDirection ( Dir )  ((Dir) = 1 - (Dir))
struct node { int data ; struct node * left , * right ; } ; node * newNode ( int data ) { node * temp = new node ; temp -> data = data ; temp -> left = temp -> right = NULL ; return temp ; } void modifiedLevelOrder ( struct node * root ) { if ( ! root ) return ; int dir = LEFT ; struct node * temp ; queue < struct node * > Q ; stack < struct node * > S ; S . push ( root ) ; while ( ! Q . empty ( ) || ! S . empty ( ) ) { while ( ! S . empty ( ) ) { temp = S . top ( ) ; S . pop ( ) ; cout << temp -> data << " ▁ " ; if ( dir == LEFT ) { if ( temp -> left ) Q . push ( temp -> left ) ; if ( temp -> right ) Q . push ( temp -> right ) ; } else { if ( temp -> right ) Q . push ( temp -> right ) ; if ( temp -> left ) Q . push ( temp -> left ) ; } } cout << endl ; while ( ! Q . empty ( ) ) { temp = Q . front ( ) ; Q . pop ( ) ; cout << temp -> data << " ▁ " ; if ( dir == LEFT ) { if ( temp -> left ) S . push ( temp -> left ) ; if ( temp -> right ) S . push ( temp -> right ) ; } else { if ( temp -> right ) S . push ( temp -> right ) ; if ( temp -> left ) S . push ( temp -> left ) ; } } cout << endl ; ChangeDirection ( dir ) ; } } 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 -> 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 ( 3 ) ; root -> left -> right -> right = newNode ( 1 ) ; root -> right -> left -> left = newNode ( 4 ) ; root -> right -> left -> right = newNode ( 2 ) ; root -> right -> right -> left = newNode ( 7 ) ; root -> right -> right -> right = newNode ( 2 ) ; root -> left -> right -> left -> left = newNode ( 16 ) ; root -> left -> right -> left -> right = newNode ( 17 ) ; root -> right -> left -> right -> left = newNode ( 18 ) ; root -> right -> right -> left -> right = newNode ( 19 ) ; modifiedLevelOrder ( root ) ; return 0 ; }

Class/struct names: node