dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int parent [ 26 ] ; int find ( int x ) { if ( x != parent [ x ] ) return parent [ x ] = find ( parent [ x ] ) ; return x ; } void join ( int x , int y ) { int px = find ( x ) ; int pz = find ( y ) ; if ( px != pz ) { parent [ pz ] = px ; } } bool convertible ( string s1 , string s2 ) { map < int , int > mp ; for ( int i = 0 ; i < s1 . size ( ) ; i ++ ) { if ( mp . find ( s1 [ i ] - ' a ' ) == mp . end ( ) ) { mp [ s1 [ i ] - ' a ' ] = s2 [ i ] - ' a ' ; } else { if ( mp [ s1 [ i ] - ' a ' ] != s2 [ i ] - ' a ' ) return false ; } } for ( auto it : mp ) { if ( it . first == it . second ) continue ; else { if ( find ( it . first ) == find ( it . second ) ) return false ; else join ( it . first , it . second ) ; } } return true ; } void initialize ( ) { for ( int i = 0 ; i < 26 ; i ++ ) { parent [ i ] = i ; } } int main ( ) { string s1 , s2 ; s1 = " abbcaa " ; s2 = " bccdbb " ; initialize ( ) ; if ( convertible ( s1 , s2 ) ) cout << " Yes " << endl ; else cout << " No " << endl ; return 0 ; }

Index/key variables: i, pz, x
Accumulator variables: i, stdc
Iterator variables: i, it
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define SIZE  26
void SieveOfEratosthenes ( bool prime [ ] , int p_size ) { prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int p = 2 ; p * p <= p_size ; p ++ ) { if ( prime [ p ] ) { for ( int i = p * 2 ; i <= p_size ; i += p ) prime [ i ] = false ; } } } void printChar ( string str , int n ) { bool prime [ n + 1 ] ; memset ( prime , true , sizeof ( prime ) ) ; SieveOfEratosthenes ( prime , str . length ( ) + 1 ) ; int freq [ SIZE ] ; memset ( freq , 0 , sizeof ( freq ) ) ; for ( int i = 0 ; i < n ; i ++ ) freq [ str [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < n ; i ++ ) { if ( prime [ freq [ str [ i ] - ' a ' ] ] ) { cout << str [ i ] ; } } } int main ( ) { string str = " geeksforgeeks " ; int n = str . length ( ) ; printChar ( str , n ) ; return 0 ; }

Index/key variables: SIZE, i, p
Accumulator variables: i, p, stdc
Iterator variables: i, p
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define SIZE  26
void printChar ( string str , int n ) { int freq [ SIZE ] ; memset ( freq , 0 , sizeof ( freq ) ) ; for ( int i = 0 ; i < n ; i ++ ) freq [ str [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < n ; i ++ ) { if ( freq [ str [ i ] - ' a ' ] % 2 == 0 ) { cout << str [ i ] ; } } } int main ( ) { string str = " geeksforgeeks " ; int n = str . length ( ) ; printChar ( str , n ) ; return 0 ; }

Index/key variables: SIZE, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; bool CompareAlphanumeric ( string & str1 , string & str2 ) { int i , j ; i = 0 ; j = 0 ; int len1 = str1 . size ( ) ; int len2 = str2 . size ( ) ; while ( i <= len1 && j <= len2 ) { while ( i < len1 && ( ! ( ( str1 [ i ] >= ' a ' && str1 [ i ] <= ' z ' ) || ( str1 [ i ] >= ' A ' && str1 [ i ] <= ' Z ' ) || ( str1 [ i ] >= '0' && str1 [ i ] <= '9' ) ) ) ) { i ++ ; } while ( j < len2 && ( ! ( ( str2 [ j ] >= ' a ' && str2 [ j ] <= ' z ' ) || ( str2 [ j ] >= ' A ' && str2 [ j ] <= ' Z ' ) || ( str2 [ j ] >= '0' && str2 [ j ] <= '9' ) ) ) ) { j ++ ; } if ( i == len1 && j == len2 ) return true ; else if ( str1 [ i ] != str2 [ j ] ) return false ; else { i ++ ; j ++ ; } } return false ; } void CompareAlphanumericUtil ( string str1 , string str2 ) { bool res ; res = CompareAlphanumeric ( str1 , str2 ) ; if ( res == true ) cout << " Equal " << endl ; else cout << " Unequal " << endl ; } int main ( ) { string str1 , str2 ; str1 = " Ram , ▁ Shyam " ; str2 = " ▁ Ram ▁ - ▁ Shyam . " ; CompareAlphanumericUtil ( str1 , str2 ) ; str1 = " abc123" ; str2 = "123abc " ; CompareAlphanumericUtil ( str1 , str2 ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void solveQueries ( string str , vector < vector < int > > & query ) { int len = str . size ( ) ; int Q = query . size ( ) ; int pre [ len ] [ 26 ] ; memset ( pre , 0 , sizeof pre ) ; for ( int i = 0 ; i < len ; i ++ ) { pre [ i ] [ str [ i ] - ' a ' ] ++ ; if ( i ) { for ( int j = 0 ; j < 26 ; j ++ ) pre [ i ] [ j ] += pre [ i - 1 ] [ j ] ; } } for ( int i = 0 ; i < Q ; i ++ ) { int l = query [ i ] [ 0 ] ; int r = query [ i ] [ 1 ] ; int maxi = 0 ; char c = ' a ' ; for ( int j = 0 ; j < 26 ; j ++ ) { int times = pre [ r ] [ j ] ; if ( l ) times -= pre [ l - 1 ] [ j ] ; if ( times > maxi ) { maxi = times ; c = char ( ' a ' + j ) ; } } cout << " Query ▁ " << i + 1 << " : ▁ " << c << endl ; } } int main ( ) { string str = " striver " ; vector < vector < int > > query ; query . push_back ( { 0 , 1 } ) ; query . push_back ( { 1 , 6 } ) ; query . push_back ( { 5 , 6 } ) ; solveQueries ( str , query ) ; }

Index/key variables: i, j, len, r
Accumulator variables: i, j, stdc, times
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool startsWith ( string str , string pre ) { int strLen = str . length ( ) ; int preLen = pre . length ( ) ; int i = 0 , j = 0 ; while ( i < strLen && j < preLen ) { if ( str [ i ] != pre [ j ] ) return false ; i ++ ; j ++ ; } return true ; } bool endsWith ( string str , string suff ) { int i = str . length ( ) - 0 ; int j = suff . length ( ) - 0 ; while ( i >= 0 && j >= 0 ) { if ( str [ i ] != suff [ j ] ) return false ; i -- ; j -- ; } return true ; } bool checkString ( string str , string a , string b ) { if ( str . length ( ) != a . length ( ) + b . length ( ) ) return false ; if ( startsWith ( str , a ) ) { if ( endsWith ( str , b ) ) return true ; } if ( startsWith ( str , b ) ) { if ( endsWith ( str , a ) ) return true ; } return false ; } int main ( ) { string str = " GeeksforGeeks " ; string a = " Geeksfo " ; string b = " rGeeks " ; if ( checkString ( str , a , b ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define SIZE  26
void printChar ( string str , int n ) { int freq [ SIZE ] ; memset ( freq , 0 , sizeof ( freq ) ) ; for ( int i = 0 ; i < n ; i ++ ) freq [ str [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < n ; i ++ ) { if ( freq [ str [ i ] - ' a ' ] % 2 == 1 ) { cout << str [ i ] ; } } } int main ( ) { string str = " geeksforgeeks " ; int n = str . length ( ) ; printChar ( str , n ) ; return 0 ; }

Index/key variables: SIZE, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minOperations ( string str , int n ) { int i , lastUpper = -1 , firstLower = -1 ; for ( i = n - 1 ; i >= 0 ; i -- ) { if ( isupper ( str [ i ] ) ) { lastUpper = i ; break ; } } for ( i = 0 ; i < n ; i ++ ) { if ( islower ( str [ i ] ) ) { firstLower = i ; break ; } } if ( lastUpper == -1 firstLower == -1 ) return 0 ; int countUpper = 0 ; for ( i = firstLower ; i < n ; i ++ ) { if ( isupper ( str [ i ] ) ) { countUpper ++ ; } } int countLower = 0 ; for ( i = 0 ; i < lastUpper ; i ++ ) { if ( islower ( str [ i ] ) ) { countLower ++ ; } } return min ( countLower , countUpper ) ; } int main ( ) { string str = " geEksFOrGEekS " ; int n = str . length ( ) ; cout << minOperations ( str , n ) << endl ; }

Index/key variables: i
Accumulator variables: countLower, countUpper, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int Betrothed_Sum ( int n ) { vector < int > Set ; for ( int number_1 = 1 ; number_1 < n ; number_1 ++ ) { int sum_divisor_1 = 1 ; int i = 2 ; while ( i * i <= number_1 ) { if ( number_1 % i == 0 ) { sum_divisor_1 = sum_divisor_1 + i ; if ( i * i != number_1 ) sum_divisor_1 += number_1 / i ; } i ++ ; } if ( sum_divisor_1 > number_1 ) { int number_2 = sum_divisor_1 - 1 ; int sum_divisor_2 = 1 ; int j = 2 ; while ( j * j <= number_2 ) { if ( number_2 % j == 0 ) { sum_divisor_2 += j ; if ( j * j != number_2 ) sum_divisor_2 += number_2 / j ; } j = j + 1 ; } if ( sum_divisor_2 == number_1 + 1 and number_1 <= n && number_2 <= n ) { Set . push_back ( number_1 ) ; Set . push_back ( number_2 ) ; } } } int Summ = 0 ; for ( auto i : Set ) { if ( i <= n ) Summ += i ; } return Summ ; } int main ( ) { int n = 78 ; cout << Betrothed_Sum ( n ) ; return 0 ; }

Accumulator variables: Summ, i, number_1, stdc, sum_divisor_1, sum_divisor_2
Iterator variables: i, number_1
C++ program:
#include <bits/stdc++.h>
using namespace std ; float rainDayProbability ( int a [ ] , int n ) { float count = 0 , m ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] == 1 ) count ++ ; } m = count / n ; return m ; } int main ( ) { int a [ ] = { 1 , 0 , 1 , 0 , 1 , 1 , 1 , 1 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; cout << rainDayProbability ( a , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; double Series ( int n ) { int i ; double sums = 0.0 , ser ; for ( i = 1 ; i <= n ; ++ i ) { ser = 1 / pow ( i , i ) ; sums += ser ; } return sums ; } int main ( ) { int n = 3 ; double res = Series ( n ) ; cout << res ; return 0 ; }

Accumulator variables: stdc, sums
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string lexicographicallyMaximum ( string S , int N ) { unordered_map < char , int > M ; for ( int i = 0 ; i < N ; ++ i ) { M [ S [ i ] ] ++ ; } vector < char > V ; for ( char i = ' a ' ; i < ( char ) ( ' a ' + min ( N , 25 ) ) ; ++ i ) { if ( M [ i ] == 0 ) { V . push_back ( i ) ; } } int j = V . size ( ) - 1 ; for ( int i = 0 ; i < N ; ++ i ) { if ( S [ i ] >= ( ' a ' + min ( N , 25 ) ) M [ S [ i ] ] > 1 ) { if ( V [ j ] < S [ i ] ) continue ; M [ S [ i ] ] -- ; S [ i ] = V [ j ] ; j -- ; } if ( j < 0 ) break ; } int l = 0 ; for ( int i = N - 1 ; i >= 0 ; i -- ) { if ( l > j ) break ; if ( S [ i ] >= ( ' a ' + min ( N , 25 ) ) M [ S [ i ] ] > 1 ) { M [ S [ i ] ] -- ; S [ i ] = V [ l ] ; l ++ ; } } return S ; } int main ( ) { string S = " abccefghh " ; int N = S . length ( ) ; cout << lexicographicallyMaximum ( S , N ) ; return 0 ; }

Index/key variables: i, j, l
Accumulator variables: i, j, l, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isConsistingSubarrayUtil ( int arr [ ] , int n ) { map < int , int > mp ; for ( int i = 0 ; i < n ; ++ i ) { mp [ arr [ i ] ] ++ ; } map < int , int > :: iterator it ; for ( it = mp . begin ( ) ; it != mp . end ( ) ; ++ it ) { if ( it -> second > 1 ) { return true ; } } return false ; } void isConsistingSubarray ( int arr [ ] , int N ) { if ( isConsistingSubarrayUtil ( arr , N ) ) { cout << " Yes " << endl ; } else { cout << " No " << endl ; } } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 1 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; isConsistingSubarray ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: stdc
Iterator variables: i, it
C++ program:
#include <bits/stdc++.h>
using namespace std ; set < int > createhashmap ( int Max ) { set < int > hashmap ; int curr = 1 ; int prev = 0 ; hashmap . insert ( prev ) ; while ( curr <= Max ) { hashmap . insert ( curr ) ; int temp = curr ; curr = curr + prev ; prev = temp ; } return hashmap ; } vector < bool > SieveOfEratosthenes ( int Max ) { vector < bool > isPrime ( Max , true ) ; isPrime [ 0 ] = false ; isPrime [ 1 ] = false ; for ( int p = 2 ; p * p <= Max ; p ++ ) { if ( isPrime [ p ] ) { for ( int i = p * p ; i <= Max ; i += p ) { isPrime [ i ] = false ; } } } return isPrime ; } int cntFibonacciPrime ( int arr [ ] , int N ) { int Max = arr [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { Max = max ( Max , arr [ i ] ) ; } vector < bool > isPrime = SieveOfEratosthenes ( Max ) ; set < int > hashmap = createhashmap ( Max ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == 1 ) continue ; if ( ( hashmap . count ( arr [ i ] ) ) && ! isPrime [ arr [ i ] ] ) { cout << arr [ i ] << " ▁ " ; } } } int main ( ) { int arr [ ] = { 13 , 55 , 7 , 3 , 5 , 21 , 233 , 144 , 89 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cntFibonacciPrime ( arr , N ) ; return 0 ; }

Index/key variables: i, p
Accumulator variables: i, p, stdc
Iterator variables: i, p
C++ program:
#include <bits/stdc++.h>
using namespace std ; int key ( int N ) { string num = " " + to_string ( N ) ; int ans = 0 ; int j = 0 ; for ( j = 0 ; j < num . length ( ) ; j ++ ) { if ( ( num [ j ] - 48 ) % 2 == 0 ) { int add = 0 ; int i ; for ( i = j ; j < num . length ( ) ; j ++ ) { add += num [ j ] - 48 ; if ( add % 2 == 1 ) break ; } if ( add == 0 ) { ans *= 10 ; } else { int digit = ( int ) floor ( log10 ( add ) + 1 ) ; ans *= ( pow ( 10 , digit ) ) ; ans += add ; } i = j ; } else { int add = 0 ; int i ; for ( i = j ; j < num . length ( ) ; j ++ ) { add += num [ j ] - 48 ; if ( add % 2 == 0 ) { break ; } } if ( add == 0 ) { ans *= 10 ; } else { int digit = ( int ) floor ( log10 ( add ) + 1 ) ; ans *= ( pow ( 10 , digit ) ) ; ans += add ; } i = j ; } } if ( j + 1 >= num . length ( ) ) { return ans ; } else { return ans += num [ num . length ( ) - 1 ] - 48 ; } } int main ( ) { int N = 1667848271 ; cout << key ( N ) ; return 0 ; }

Index/key variables: j
Accumulator variables: add, ans, j, stdc
Iterator variables: i, j
C++ program:
#include <iostream>
using namespace std ; void sentinelSearch ( int arr [ ] , int n , int key ) { int last = arr [ n - 1 ] ; arr [ n - 1 ] = key ; int i = 0 ; while ( arr [ i ] != key ) i ++ ; arr [ n - 1 ] = last ; if ( ( i < n - 1 ) || ( arr [ n - 1 ] == key ) ) cout << key << " ▁ is ▁ present ▁ at ▁ index ▁ " << i ; else cout << " Element ▁ Not ▁ found " ; } int main ( ) { int arr [ ] = { 10 , 20 , 180 , 30 , 60 , 50 , 110 , 100 , 70 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int key = 180 ; sentinelSearch ( arr , n , key ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maximum_middle_value ( int n , int k , int arr [ ] ) { int ans = -1 ; int low = ( n + 1 - k ) / 2 ; int high = ( n + 1 - k ) / 2 + k ; for ( int i = low ; i <= high ; i ++ ) { ans = max ( ans , arr [ i - 1 ] ) ; } return ans ; } int main ( ) { int n = 5 , k = 2 ; int arr [ ] = { 9 , 5 , 3 , 7 , 10 } ; cout << maximum_middle_value ( n , k , arr ) << endl ; n = 9 ; k = 3 ; int arr1 [ ] = { 2 , 4 , 3 , 9 , 5 , 8 , 7 , 6 , 10 } ; cout << maximum_middle_value ( n , k , arr1 ) << endl ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int ternarySearch ( int l , int r , int key , int ar [ ] ) { if ( r >= l ) { int mid1 = l + ( r - l ) / 3 ; int mid2 = r - ( r - l ) / 3 ; if ( ar [ mid1 ] == key ) { return mid1 ; } if ( ar [ mid2 ] == key ) { return mid2 ; } if ( key < ar [ mid1 ] ) { return ternarySearch ( l , mid1 - 1 , key , ar ) ; } else if ( key > ar [ mid2 ] ) { return ternarySearch ( mid2 + 1 , r , key , ar ) ; } else { return ternarySearch ( mid1 + 1 , mid2 - 1 , key , ar ) ; } } return -1 ; } int main ( ) { int l , r , p , key ; int ar [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } ; l = 0 ; r = 9 ; key = 5 ; p = ternarySearch ( l , r , key , ar ) ; cout << " Index ▁ of ▁ " << key << " ▁ is ▁ " << p << endl ; key = 50 ; p = ternarySearch ( l , r , key , ar ) ; cout << " Index ▁ of ▁ " << key << " ▁ is ▁ " << p << endl ; }

Index/key variables: mid1, mid2
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; typedef long long ll ; struct Point { int x , y ; } ; int findmin ( Point p [ ] , int n ) { int a = 0 , b = 0 , c = 0 , d = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( p [ i ] . x <= 0 ) a ++ ; else if ( p [ i ] . x >= 0 ) b ++ ; if ( p [ i ] . y >= 0 ) c ++ ; else if ( p [ i ] . y <= 0 ) d ++ ; } return min ( { a , b , c , d } ) ; } int main ( ) { Point p [ ] = { { 1 , 1 } , { 2 , 2 } , { -1 , -1 } , { -2 , 2 } } ; int n = sizeof ( p ) / sizeof ( p [ 0 ] ) ; cout << findmin ( p , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: a, b, c, d, i, stdc
Iterator variables: i
Class/struct names: Point
C++ program:
#include <bits/stdc++.h>
using namespace std ; void maxOps ( int a , int b , int c ) { int arr [ ] = { a , b , c } ; int count = 0 ; while ( 1 ) { sort ( arr , arr + 3 ) ; if ( ! arr [ 0 ] && ! arr [ 1 ] ) break ; arr [ 1 ] -= 1 ; arr [ 2 ] -= 1 ; count += 1 ; } cout << count ; } int main ( ) { int a = 4 , b = 3 , c = 2 ; maxOps ( a , b , c ) ; return 0 ; }

Accumulator variables: count, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAX  26
string getSortedString ( string s , int n ) { int lower [ MAX ] = { 0 } ; int upper [ MAX ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) { if ( islower ( s [ i ] ) ) lower [ s [ i ] - ' a ' ] ++ ; else if ( isupper ( s [ i ] ) ) upper [ s [ i ] - ' A ' ] ++ ; } int i = 0 , j = 0 ; while ( i < MAX && lower [ i ] == 0 ) i ++ ; while ( j < MAX && upper [ j ] == 0 ) j ++ ; for ( int k = 0 ; k < n ; k ++ ) { if ( islower ( s [ k ] ) ) { while ( lower [ i ] == 0 ) i ++ ; s [ k ] = ( char ) ( i + ' a ' ) ; lower [ i ] -- ; } else if ( isupper ( s [ k ] ) ) { while ( upper [ j ] == 0 ) j ++ ; s [ k ] = ( char ) ( j + ' A ' ) ; upper [ j ] -- ; } } return s ; } int main ( ) { string s = " gEeksfOrgEEkS " ; int n = s . length ( ) ; cout << getSortedString ( s , n ) ; return 0 ; }

Index/key variables: MAX, i, j, k
Accumulator variables: i, j, k, stdc
Iterator variables: i, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define SIZE  26
void printCharWithFreq ( string str ) { int n = str . size ( ) ; int freq [ SIZE ] ; memset ( freq , 0 , sizeof ( freq ) ) ; for ( int i = 0 ; i < n ; i ++ ) freq [ str [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < n ; i ++ ) { if ( freq [ str [ i ] - ' a ' ] != 0 ) { cout << str [ i ] << freq [ str [ i ] - ' a ' ] << " ▁ " ; freq [ str [ i ] - ' a ' ] = 0 ; } } } int main ( ) { string str = " geeksforgeeks " ; printCharWithFreq ( str ) ; return 0 ; }

Index/key variables: SIZE, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int main ( ) { string s [ ] = { " i " , " like " , " this " , " program " , " very " , " much " } ; string ans = " " ; for ( int i = 5 ; i >= 0 ; i -- ) { ans += s [ i ] + " ▁ " ; } cout << ( " Reversed ▁ String : " ) << endl ; cout << ( ans . substr ( 0 , ans . length ( ) - 1 ) ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
#include <iostream>
using namespace std ; bool prime [ 10000001 ] ; void swap ( int * a , int * b ) { int temp = * a ; * a = * b ; * b = temp ; } void SieveOfEratosthenes ( int n ) { memset ( prime , true , sizeof ( prime ) ) ; for ( int p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * p ; i <= n ; i += p ) prime [ i ] = false ; } } } void segregatePrimeNonPrime ( int arr [ ] , int N ) { SieveOfEratosthenes ( 10000000 ) ; int left = 0 , right = N - 1 ; while ( left < right ) { while ( prime [ arr [ left ] ] ) left ++ ; while ( ! prime [ arr [ right ] ] ) right -- ; if ( left < right ) { swap ( & arr [ left ] , & arr [ right ] ) ; left ++ ; right -- ; } } for ( int i = 0 ; i < N ; i ++ ) cout << arr [ i ] << " ▁ " ; } int main ( ) { int arr [ ] = { 2 , 3 , 4 , 6 , 7 , 8 , 9 , 10 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; segregatePrimeNonPrime ( arr , N ) ; return 0 ; }

Index/key variables: i, left, p, right
Accumulator variables: i, left, p, right, stdc
Iterator variables: i, p
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findDepthRec ( char tree [ ] , int n , int & index ) { if ( index >= n tree [ index ] == ' l ' ) return 0 ; index ++ ; int left = findDepthRec ( tree , n , index ) ; index ++ ; int right = findDepthRec ( tree , n , index ) ; return max ( left , right ) + 1 ; } int findDepth ( char tree [ ] , int n ) { int index = 0 ; findDepthRec ( tree , n , index ) ; } int main ( ) { char tree [ ] = " nlnnlll " ; int n = strlen ( tree ) ; cout << findDepth ( tree , n ) << endl ; return 0 ; }

Index/key variables: index
Accumulator variables: index, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int key ; Node * left , * right ; } ; Node * newNode ( int item ) { Node * temp = new Node ; temp -> key = item ; temp -> left = temp -> right = NULL ; return temp ; } Node * insert ( Node * node , int key ) { if ( node == NULL ) return newNode ( key ) ; if ( key < node -> key ) node -> left = insert ( node -> left , key ) ; else if ( key > node -> key ) node -> right = insert ( node -> right , key ) ; return node ; } int findMaxforN ( Node * root , int N ) { if ( root == NULL ) return -1 ; if ( root -> key == N ) return N ; else if ( root -> key < N ) { int k = findMaxforN ( root -> right , N ) ; if ( k == -1 ) return root -> key ; else return k ; } else if ( root -> key > N ) return findMaxforN ( root -> left , N ) ; } int main ( ) { int N = 4 ; Node * root = insert ( root , 25 ) ; insert ( root , 2 ) ; insert ( root , 1 ) ; insert ( root , 3 ) ; insert ( root , 12 ) ; insert ( root , 9 ) ; insert ( root , 21 ) ; insert ( root , 19 ) ; insert ( root , 25 ) ; printf ( " % d " , findMaxforN ( root , N ) ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int key ; Node * left , * right ; } ; Node * newNode ( int item ) { Node * temp = new Node ; temp -> key = item ; temp -> left = temp -> right = NULL ; return temp ; } Node * insert ( Node * node , int key ) { if ( node == NULL ) return newNode ( key ) ; if ( key < node -> key ) node -> left = insert ( node -> left , key ) ; else if ( key > node -> key ) node -> right = insert ( node -> right , key ) ; return node ; } void findMaxforN ( Node * root , int N ) { while ( root != NULL && root -> right != NULL ) { if ( N > root -> key && N >= root -> right -> key ) root = root -> right ; else if ( N < root -> key ) root = root -> left ; else break ; } if ( root == NULL root -> key > N ) cout << -1 ; else cout << root -> key ; } int main ( ) { int N = 50 ; Node * root = insert ( root , 5 ) ; insert ( root , 2 ) ; insert ( root , 1 ) ; insert ( root , 3 ) ; insert ( root , 12 ) ; insert ( root , 9 ) ; insert ( root , 21 ) ; insert ( root , 19 ) ; insert ( root , 25 ) ; findMaxforN ( root , N ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { struct Node * left , * right ; int data ; } ; Node * createNode ( int x ) { Node * p = new Node ; p -> data = x ; p -> left = p -> right = NULL ; return p ; } void insertNode ( struct Node * root , int x ) { Node * p = root , * q = NULL ; while ( p != NULL ) { q = p ; if ( p -> data < x ) p = p -> right ; else p = p -> left ; } if ( q == NULL ) p = createNode ( x ) ; else { if ( q -> data < x ) q -> right = createNode ( x ) ; else q -> left = createNode ( x ) ; } } int maxelpath ( Node * q , int x ) { Node * p = q ; int mx = INT_MIN ; while ( p -> data != x ) { if ( p -> data > x ) { mx = max ( mx , p -> data ) ; p = p -> left ; } else { mx = max ( mx , p -> data ) ; p = p -> right ; } } return max ( mx , x ) ; } int maximumElement ( struct Node * root , int x , int y ) { Node * p = root ; while ( ( x < p -> data && y < p -> data ) || ( x > p -> data && y > p -> data ) ) { if ( x < p -> data && y < p -> data ) p = p -> left ; else if ( x > p -> data && y > p -> data ) p = p -> right ; } return max ( maxelpath ( p , x ) , maxelpath ( p , y ) ) ; } int main ( ) { int arr [ ] = { 18 , 36 , 9 , 6 , 12 , 10 , 1 , 8 } ; int a = 1 , b = 10 ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; struct Node * root = createNode ( arr [ 0 ] ) ; for ( int i = 1 ; i < n ; i ++ ) insertNode ( root , arr [ i ] ) ; cout << maximumElement ( root , a , b ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
Class/struct names: Node