dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; class Node { public : int data ; Node * left , * right ; Node ( int item ) { data = item ; left = right = NULL ; } } ; int findLevel ( Node * root , int data ) { if ( data < root -> data ) return -1 ; if ( data == root -> data ) return 0 ; int cur_level = 0 ; while ( true ) { cur_level ++ ; root = root -> left ; if ( root -> data == data ) return -2 ; if ( root -> data < data && ( root -> left == NULL root -> left -> data > data ) ) { break ; } } return cur_level ; } int traversePath ( Node * root , vector < int > path ) { for ( int i = 0 ; i < path . size ( ) ; i ++ ) { int direction = path [ i ] ; if ( direction == 0 ) { if ( root -> left == NULL ) return -1 ; root = root -> left ; } else { if ( root -> right == NULL ) return -1 ; root = root -> right ; } } return root -> data ; } vector < int > generateGray ( int n , int x ) { vector < int > gray ; int i = 0 ; while ( x > 0 ) { gray . push_back ( x % 2 ) ; x = x / 2 ; i ++ ; } reverse ( gray . begin ( ) , gray . end ( ) ) ; for ( int j = 0 ; j < n - i ; j ++ ) gray . insert ( gray . begin ( ) , 0 ) ; return gray ; } bool binarySearch ( Node * root , int start , int end , int data , int level ) { if ( end >= start ) { int mid = ( start + end ) / 2 ; vector < int > encoding = generateGray ( level , mid ) ; int element_found = traversePath ( root , encoding ) ; if ( element_found == -1 ) return binarySearch ( root , start , mid - 1 , data , level ) ; if ( element_found == data ) return true ; if ( element_found < data ) return binarySearch ( root , mid + 1 , end , data , level ) ; else return binarySearch ( root , start , mid - 1 , data , level ) ; } return false ; } bool findKey ( Node * root , int data ) { int level = findLevel ( root , data ) ; if ( level == -1 ) return false ; if ( level == -2 ) return true ; return binarySearch ( root , 0 , ( int ) pow ( 2 , level ) - 1 , data , level ) ; } int main ( ) { Node * root = new Node ( 5 ) ; root -> left = new Node ( 8 ) ; root -> right = new Node ( 10 ) ; root -> left -> left = new Node ( 13 ) ; root -> left -> right = new Node ( 23 ) ; root -> right -> left = new Node ( 25 ) ; root -> right -> right = new Node ( 30 ) ; root -> left -> left -> left = new Node ( 32 ) ; root -> left -> left -> right = new Node ( 40 ) ; root -> left -> right -> left = new Node ( 50 ) ; int arr [ ] = { 5 , 8 , 9 } ; int n = sizeof ( arr ) / sizeof ( int ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( findKey ( root , arr [ i ] ) ) cout << ( " Yes " ) << endl ; else cout << ( " No " ) << endl ; } }

Index/key variables: i
Accumulator variables: cur_level, i, j, stdc
Iterator variables: i, j
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
void reverseArray ( int arr [ ] , int start , int end ) { while ( start < end ) { std :: swap ( arr [ start ] , arr [ end ] ) ; start ++ ; end -- ; } } void rightRotate ( int arr [ ] , int d , int n ) { reverseArray ( arr , 0 , n - 1 ) ; reverseArray ( arr , 0 , d - 1 ) ; reverseArray ( arr , d , n - 1 ) ; } void printArray ( int arr [ ] , int size ) { for ( int i = 0 ; i < size ; i ++ ) std :: cout << arr [ i ] << " ▁ " ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 3 ; rightRotate ( arr , k , n ) ; printArray ( arr , n ) ; return 0 ; }

Index/key variables: end, i, start
Accumulator variables: end, i, start, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; Node * left , * right ; } ; void printOddNodes ( Node * root ) { if ( root == NULL ) return ; queue < Node * > q ; q . push ( root ) ; bool isOdd = true ; while ( 1 ) { int nodeCount = q . size ( ) ; if ( nodeCount == 0 ) break ; while ( nodeCount > 0 ) { Node * node = q . front ( ) ; if ( isOdd ) cout << node -> data << " ▁ " ; q . pop ( ) ; if ( node -> left != NULL ) q . push ( node -> left ) ; if ( node -> right != NULL ) q . push ( node -> right ) ; nodeCount -- ; } isOdd = ! isOdd ; } } struct Node * newNode ( int data ) { struct Node * node = new Node ; node -> data = data ; node -> left = node -> right = NULL ; return ( node ) ; } int main ( ) { struct Node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 5 ) ; printOddNodes ( root ) ; return 0 ; }

Accumulator variables: nodeCount, stdc
Boolean variables: isOdd
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxHamming ( int arr [ ] , int n ) { int brr [ 2 * n + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) brr [ i ] = arr [ i ] ; for ( int i = 0 ; i < n ; i ++ ) brr [ n + i ] = arr [ i ] ; int maxHam = 0 ; for ( int i = 1 ; i < n ; i ++ ) { int currHam = 0 ; for ( int j = i , k = 0 ; j < ( i + n ) ; j ++ , k ++ ) if ( brr [ j ] != arr [ k ] ) currHam ++ ; if ( currHam == n ) return n ; maxHam = max ( maxHam , currHam ) ; } return maxHam ; } int main ( ) { int arr [ ] = { 2 , 4 , 6 , 8 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << maxHamming ( arr , n ) ; return 0 ; }

Index/key variables: i, j, k
Accumulator variables: currHam, i, j, k, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void leftRotate ( int arr [ ] , int n , int k ) { int mod = k % n ; for ( int i = 0 ; i < n ; i ++ ) cout << ( arr [ ( mod + i ) % n ] ) << " ▁ " ; cout << " STRNEWLINE " ; } int main ( ) { int arr [ ] = { 1 , 3 , 5 , 7 , 9 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 2 ; leftRotate ( arr , n , k ) ; k = 3 ; leftRotate ( arr , n , k ) ; k = 4 ; leftRotate ( arr , n , k ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <algorithm>
#include <iostream>
using namespace std ; struct circle { int start , end ; } ; bool comp ( circle a , circle b ) { if ( a . end == b . end ) return a . start < b . start ; return a . end < b . end ; } void CountCircles ( int c [ ] , int r [ ] , int n ) { circle diameter [ n ] ; for ( int i = 0 ; i < n ; ++ i ) { diameter [ i ] . start = c [ i ] - r [ i ] ; diameter [ i ] . end = c [ i ] + r [ i ] ; } sort ( diameter , diameter + n , comp ) ; int count = 0 ; int cur = diameter [ 0 ] . end ; for ( int i = 1 ; i < n ; ++ i ) { if ( diameter [ i ] . start > cur ) { cur = diameter [ i ] . end ; } else count ++ ; } cout << count << " STRNEWLINE " ; } int main ( ) { int c [ ] = { 1 , 2 , 3 , 4 } ; int r [ ] = { 1 , 1 , 1 , 1 } ; int n = sizeof ( c ) / sizeof ( int ) ; CountCircles ( c , r , n ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: count
Iterator variables: i
Class/struct names: circle
C++ program:
#include <bits/stdc++.h>
#include <iostream>
using namespace std ; void leftRotate ( int arr [ ] , int k , int n ) { rotate ( arr , arr + ( k % n ) , arr + n ) ; for ( int i = 0 ; i < n ; i ++ ) cout << arr [ i ] << " ▁ " ; cout << " STRNEWLINE " ; } int main ( ) { int arr [ ] = { 1 , 3 , 5 , 7 , 9 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 2 ; leftRotate ( arr , k , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findElement ( int arr [ ] , int ranges [ ] [ 2 ] , int rotations , int index ) { for ( int i = rotations - 1 ; i >= 0 ; i -- ) { int left = ranges [ i ] [ 0 ] ; int right = ranges [ i ] [ 1 ] ; if ( left <= index && right >= index ) { if ( index == left ) index = right ; else index -- ; } } return arr [ index ] ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int rotations = 2 ; int ranges [ rotations ] [ 2 ] = { { 0 , 2 } , { 0 , 3 } } ; int index = 1 ; cout << findElement ( arr , ranges , rotations , index ) ; return 0 ; }

Index/key variables: i, index, rotations
Accumulator variables: i, index, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string sort ( string s ) { char c [ s . length ( ) + 1 ] ; strcpy ( c , s . c_str ( ) ) ; sort ( c , c + s . length ( ) ) ; int al_c = 0 , nu_c = 0 ; while ( c [ al_c ] < 97 ) al_c ++ ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s [ i ] < 97 ) s [ i ] = c [ nu_c ++ ] ; else s [ i ] = c [ al_c ++ ] ; } return s ; } int main ( ) { string s = " d4c3b2a1" ; cout << sort ( s ) ; return 0 ; }

Index/key variables: al_c, i
Accumulator variables: al_c, i, nu_c, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void splitArr ( int arr [ ] , int n , int k ) { for ( int i = 0 ; i < k ; i ++ ) { int x = arr [ 0 ] ; for ( int j = 0 ; j < n - 1 ; ++ j ) arr [ j ] = arr [ j + 1 ] ; arr [ n - 1 ] = x ; } } int main ( ) { int arr [ ] = { 12 , 10 , 5 , 6 , 52 , 36 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int position = 2 ; splitArr ( arr , 6 , position ) ; for ( int i = 0 ; i < n ; ++ i ) printf ( " % d ▁ " , arr [ i ] ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void splitArr ( int arr [ ] , int length , int rotation ) { int tmp [ length * 2 ] = { 0 } ; for ( int i = 0 ; i < length ; i ++ ) { tmp [ i ] = arr [ i ] ; tmp [ i + length ] = arr [ i ] ; } for ( int i = rotation ; i < rotation + length ; i ++ ) { arr [ i - rotation ] = tmp [ i ] ; } } int main ( ) { int arr [ ] = { 12 , 10 , 5 , 6 , 52 , 36 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int position = 2 ; splitArr ( arr , n , position ) ; for ( int i = 0 ; i < n ; ++ i ) printf ( " % d ▁ " , arr [ i ] ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void swap ( int & a , int & b ) { int temp = a ; a = b ; b = temp ; } void sort_shell_metzner ( int arr [ ] , int n ) { int i , j , k , l , m , temp ; m = n ; while ( m > 0 ) { m /= 2 ; k = n - m ; j = 0 ; do { i = j ; do { l = i + m ; if ( arr [ i ] > arr [ l ] ) { swap ( arr [ i ] , arr [ l ] ) ; i -= m ; } else break ; } while ( i >= 0 ) ; j ++ ; } while ( j <= k ) ; } } void printArray ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) cout << arr [ i ] << " ▁ " ; } int main ( ) { int arr [ ] = { 0 , -2 , 8 , 5 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; sort_shell_metzner ( arr , n ) ; printArray ( arr , n ) ; return 0 ; }

Index/key variables: i, l
Accumulator variables: i, j, m, stdc
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; void fixArray ( int ar [ ] , int n ) { int i , j , temp ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < n ; j ++ ) { if ( ar [ j ] == i ) { temp = ar [ j ] ; ar [ j ] = ar [ i ] ; ar [ i ] = temp ; break ; } } } for ( i = 0 ; i < n ; i ++ ) { if ( ar [ i ] != i ) { ar [ i ] = -1 ; } } cout << " Array ▁ after ▁ Rearranging " << endl ; for ( i = 0 ; i < n ; i ++ ) { cout << ar [ i ] << " ▁ " ; } } int main ( ) { int n , ar [ ] = { -1 , -1 , 6 , 1 , 9 , 3 , 2 , -1 , 4 , -1 } ; n = sizeof ( ar ) / sizeof ( ar [ 0 ] ) ; fixArray ( ar , n ) ; }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getFinalSum ( int a [ ] , int n , pair < int , int > queries [ ] , int q , int k ) { int answer = 0 ; for ( int i = 0 ; i < n ; i ++ ) answer += a [ i ] ; vector < int > contribution ; for ( int i = 0 ; i < q ; i ++ ) { contribution . push_back ( queries [ i ] . second - queries [ i ] . first + 1 ) ; } sort ( contribution . begin ( ) , contribution . end ( ) , greater < int > ( ) ) ; int i = 0 ; while ( i < k ) { answer += contribution [ i ] ; i ++ ; } return answer ; } int main ( ) { int a [ ] = { 1 , 1 , 2 , 2 , 2 , 3 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; pair < int , int > queries [ ] = { { 0 , 4 } , { 1 , 2 } , { 2 , 5 } , { 2 , 3 } , { 2 , 4 } } ; int q = sizeof ( queries ) / sizeof ( queries [ 0 ] ) ; int k = 3 ; cout << getFinalSum ( a , n , queries , q , k ) ; return 0 ; }

Index/key variables: i
Accumulator variables: answer, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int answerQuery ( pair < int , int > arr [ ] , int l , int r ) { int answer = abs ( arr [ l - 1 ] . second - arr [ r - 1 ] . second ) ; return answer ; } void solveQueries ( int a [ ] , int n , int q [ ] [ 2 ] , int m ) { pair < int , int > arr [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] . first = a [ i ] ; arr [ i ] . second = i ; } sort ( arr , arr + n ) ; for ( int i = 0 ; i < m ; i ++ ) cout << answerQuery ( arr , q [ i ] [ 0 ] , q [ i ] [ 1 ] ) << endl ; } int main ( ) { int a [ ] = { 1 , 5 , 4 , 2 , 8 , 6 , 7 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; int q [ ] [ 2 ] = { { 2 , 5 } , { 1 , 3 } , { 1 , 5 } , { 3 , 6 } } ; int m = sizeof ( q ) / sizeof ( q [ 0 ] ) ; solveQueries ( a , n , q , m ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; 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 findFullNode ( Node * root ) { if ( root != NULL ) { findFullNode ( root -> left ) ; if ( root -> left != NULL && root -> right != NULL ) cout << root -> data << " ▁ " ; findFullNode ( root -> right ) ; } } int main ( ) { Node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 4 ) ; root -> right -> left = newNode ( 5 ) ; root -> right -> right = newNode ( 6 ) ; root -> right -> left -> right = newNode ( 7 ) ; root -> right -> right -> right = newNode ( 8 ) ; root -> right -> left -> right -> left = newNode ( 9 ) ; findFullNode ( root ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include " iostream "
#include " queue "
#include " unordered _ map "
using namespace std ; void findElementsAfterDel ( int arr [ ] , int m , int del [ ] , int n , int k ) { unordered_map < int , int > mp ; for ( int i = 0 ; i < n ; ++ i ) { mp [ del [ i ] ] ++ ; } priority_queue < int > heap ; for ( int i = 0 ; i < m ; ++ i ) { if ( mp . find ( arr [ i ] ) != mp . end ( ) ) { mp [ arr [ i ] ] -- ; if ( mp [ arr [ i ] ] == 0 ) mp . erase ( arr [ i ] ) ; } else heap . push ( arr [ i ] ) ; } for ( int i = 0 ; i < k ; ++ i ) { cout << heap . top ( ) << " ▁ " ; heap . pop ( ) ; } } int main ( ) { int array [ ] = { 5 , 12 , 33 , 4 , 56 , 12 , 20 } ; int m = sizeof ( array ) / sizeof ( array [ 0 ] ) ; int del [ ] = { 12 , 56 , 5 } ; int n = sizeof ( del ) / sizeof ( del [ 0 ] ) ; int k = 3 ; findElementsAfterDel ( array , m , del , n , k ) ; return 0 ; }

Index/key variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void kThLexString ( string st , int k , int n ) { set < string > z ; for ( int i = 0 ; i < n ; i ++ ) { string pp ; for ( int j = i ; j < i + k ; j ++ ) { if ( j >= n ) break ; pp += st [ j ] ; z . insert ( pp ) ; } } vector < string > fin ( z . begin ( ) , z . end ( ) ) ; sort ( fin . begin ( ) , fin . end ( ) ) ; cout << fin [ k - 1 ] ; } int main ( ) { string s = " geeksforgeeks " ; int k = 5 ; int n = s . length ( ) ; kThLexString ( s , k , n ) ; }

Index/key variables: j
Accumulator variables: i, j, pp, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void rearrangeArr ( int arr [ ] , int n ) { int evenPos = n / 2 ; int oddPos = n - evenPos ; int tempArr [ n ] ; for ( int i = 0 ; i < n ; i ++ ) tempArr [ i ] = arr [ i ] ; sort ( tempArr , tempArr + n ) ; int j = oddPos - 1 ; for ( int i = 0 ; i < n ; i += 2 ) { arr [ i ] = tempArr [ j ] ; j -- ; } j = oddPos ; for ( int i = 1 ; i < n ; i += 2 ) { arr [ i ] = tempArr [ j ] ; j ++ ; } for ( int i = 0 ; i < n ; i ++ ) cout << arr [ i ] << " ▁ " ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 } ; int size = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; rearrangeArr ( arr , size ) ; return 0 ; }

Index/key variables: i, j, n
Accumulator variables: i, j, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * next , * prev ; } ; int countTriplets ( struct Node * head , int x ) { struct Node * ptr1 , * ptr2 , * ptr3 ; int count = 0 ; for ( ptr1 = head ; ptr1 != NULL ; ptr1 = ptr1 -> next ) for ( ptr2 = ptr1 -> next ; ptr2 != NULL ; ptr2 = ptr2 -> next ) for ( ptr3 = ptr2 -> next ; ptr3 != NULL ; ptr3 = ptr3 -> next ) if ( ( ptr1 -> data * ptr2 -> data * ptr3 -> data ) == x ) count ++ ; return count ; } void insert ( struct Node * * head , int data ) { struct Node * temp = new Node ( ) ; temp -> data = data ; temp -> next = temp -> prev = NULL ; if ( ( * head ) == NULL ) ( * head ) = temp ; else { temp -> next = * head ; ( * head ) -> prev = temp ; ( * head ) = temp ; } } int main ( ) { struct Node * head = NULL ; insert ( & head , 9 ) ; insert ( & head , 8 ) ; insert ( & head , 6 ) ; insert ( & head , 5 ) ; insert ( & head , 4 ) ; insert ( & head , 2 ) ; insert ( & head , 1 ) ; int x = 8 ; cout << " Count ▁ = ▁ " << countTriplets ( head , x ) ; return 0 ; }

Accumulator variables: count, stdc
Iterator variables: ptr1, ptr2, ptr3
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool prime [ 100005 ] ; void SieveOfEratosthenes ( int n ) { memset ( prime , true , sizeof ( prime ) ) ; prime [ 1 ] = false ; for ( int p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i <= n ; i += p ) prime [ i ] = false ; } } } void sortedArray ( int arr [ ] , int n ) { SieveOfEratosthenes ( 100005 ) ; std :: vector < int > v ; for ( int i = 0 ; i < n ; ++ i ) { if ( prime [ arr [ i ] ] == 0 ) v . push_back ( arr [ i ] ) ; } sort ( v . begin ( ) , v . end ( ) ) ; int j = 0 ; for ( int i = 0 ; i < n ; ++ i ) { if ( prime [ arr [ i ] ] == true ) cout << arr [ i ] << " ▁ " ; else { cout << v [ j ] << " ▁ " ; j ++ ; } } } int main ( ) { int n = 6 ; int arr [ ] = { 100 , 11 , 500 , 2 , 17 , 1 } ; sortedArray ( arr , n ) ; return 0 ; }

Index/key variables: i, j, p
Accumulator variables: i, j, p, stdc
Iterator variables: i, p
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int key ; Node * left , * right ; } ; Node * newNode ( int key ) { Node * node = new Node ; node -> key = key ; node -> left = node -> right = NULL ; return ( node ) ; } int addBT ( Node * root ) { if ( root == NULL ) return 0 ; return ( root -> key + addBT ( root -> left ) + addBT ( root -> right ) ) ; } 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 -> right -> left -> right = newNode ( 8 ) ; int sum = addBT ( root ) ; cout << " Sum ▁ of ▁ all ▁ the ▁ elements ▁ is : ▁ " << sum << endl ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int MaxSumDifference ( int a [ ] , int n ) { vector < int > finalSequence ; sort ( a , a + n ) ; for ( int i = 0 ; i < n / 2 ; ++ i ) { finalSequence . push_back ( a [ i ] ) ; finalSequence . push_back ( a [ n - i - 1 ] ) ; } if ( n % 2 != 0 ) finalSequence . push_back ( a [ n / 2 ] ) ; int MaximumSum = 0 ; for ( int i = 0 ; i < n - 1 ; ++ i ) { MaximumSum = MaximumSum + abs ( finalSequence [ i ] - finalSequence [ i + 1 ] ) ; } MaximumSum = MaximumSum + abs ( finalSequence [ n - 1 ] - finalSequence [ 0 ] ) ; return MaximumSum ; } int main ( ) { int a [ ] = { 1 , 2 , 4 , 8 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; cout << MaxSumDifference ( a , n ) << endl ; }

Index/key variables: i
Accumulator variables: stdc
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int minSwap ( int * arr , int n , int k ) { int count = 0 ; for ( int i = 0 ; i < n ; ++ i ) if ( arr [ i ] <= k ) ++ count ; int bad = 0 ; for ( int i = 0 ; i < count ; ++ i ) if ( arr [ i ] > k ) ++ bad ; int ans = bad ; for ( int i = 0 , j = count ; j < n ; ++ i , ++ j ) { if ( arr [ i ] > k ) -- bad ; if ( arr [ j ] > k ) ++ bad ; ans = min ( ans , bad ) ; } return ans ; } int main ( ) { int arr [ ] = { 2 , 1 , 5 , 6 , 3 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 3 ; cout << minSwap ( arr , n , k ) << " STRNEWLINE " ; int arr1 [ ] = { 2 , 7 , 9 , 5 , 8 , 7 , 4 } ; n = sizeof ( arr1 ) / sizeof ( arr1 [ 0 ] ) ; k = 5 ; cout << minSwap ( arr1 , n , k ) ; return 0 ; }

Index/key variables: i, j
Iterator variables: i
C++ program:
#include <iostream>
void printArray ( int array [ ] , int length ) { std :: cout << " [ " ; for ( int i = 0 ; i < length ; i ++ ) { std :: cout << array [ i ] ; if ( i < ( length - 1 ) ) std :: cout << " , ▁ " ; else std :: cout << " ] " << std :: endl ; } } void reverse ( int array [ ] , int start , int end ) { while ( start < end ) { int temp = array [ start ] ; array [ start ] = array [ end ] ; array [ end ] = temp ; start ++ ; end -- ; } } void rearrange ( int array [ ] , int start , int end ) { if ( start == end ) return ; rearrange ( array , ( start + 1 ) , end ) ; if ( array [ start ] >= 0 ) { reverse ( array , ( start + 1 ) , end ) ; reverse ( array , start , end ) ; } } int main ( ) { int array [ ] = { -12 , -11 , -13 , -5 , -6 , 7 , 5 , 3 , 6 } ; int length = ( sizeof ( array ) / sizeof ( array [ 0 ] ) ) ; int countNegative = 0 ; for ( int i = 0 ; i < length ; i ++ ) { if ( array [ i ] < 0 ) countNegative ++ ; } std :: cout << " array : ▁ " ; printArray ( array , length ) ; rearrange ( array , 0 , ( length - 1 ) ) ; reverse ( array , countNegative , ( length - 1 ) ) ; std :: cout << " rearranged ▁ array : ▁ " ; printArray ( array , length ) ; return 0 ; }

Index/key variables: end, i, start
Accumulator variables: countNegative, end, i, start
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void mergeArray ( int arr1 [ ] , int arr2 [ ] , int n , int m ) { for ( int i = 0 ; i < n ; i ++ ) { if ( arr1 [ i ] > arr2 [ 0 ] ) { int temp = arr1 [ i ] ; arr1 [ i ] = arr2 [ 0 ] ; arr2 [ 0 ] = temp ; int firstElement = arr2 [ 0 ] ; int k ; for ( k = 1 ; k < m && arr2 [ k ] < firstElement ; k ++ ) { arr2 [ k - 1 ] = arr2 [ k ] ; } arr2 [ k - 1 ] = firstElement ; } } for ( int i = 0 ; i < n ; i ++ ) { cout << arr1 [ i ] << " ▁ " ; } cout << endl ; for ( int i = 0 ; i < m ; i ++ ) { cout << arr2 [ i ] << " ▁ " ; } } int main ( ) { int arr1 [ ] = { 1 , 3 , 5 , 7 } ; int arr2 [ ] = { 0 , 2 , 6 , 8 , 9 } ; int n = arr1 . length , m = arr2 . length ; mergeArray ( arr1 , arr2 , n , m ) ; }

Index/key variables: i, k
Accumulator variables: i, k, stdc
Iterator variables: i, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MAX_CHAR = 26 ; struct Trie { int index ; Trie * child [ MAX_CHAR ] ; Trie ( ) { for ( int i = 0 ; i < MAX_CHAR ; i ++ ) child [ i ] = NULL ; index = -1 ; } } ; void insert ( Trie * root , string str , int index ) { Trie * node = root ; for ( int i = 0 ; i < str . size ( ) ; i ++ ) { char ind = str [ i ] - ' a ' ; if ( ! node -> child [ ind ] ) node -> child [ ind ] = new Trie ( ) ; node = node -> child [ ind ] ; } node -> index = index ; } bool preorder ( Trie * node , string arr [ ] ) { if ( node == NULL ) return false ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) { if ( node -> child [ i ] != NULL ) { if ( node -> child [ i ] -> index != -1 ) cout << arr [ node -> child [ i ] -> index ] << endl ; preorder ( node -> child [ i ] , arr ) ; } } } void printSorted ( string arr [ ] , int n ) { Trie * root = new Trie ( ) ; for ( int i = 0 ; i < n ; i ++ ) insert ( root , arr [ i ] , i ) ; preorder ( root , arr ) ; } int main ( ) { string arr [ ] = { " abc " , " xy " , " bcd " } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; printSorted ( arr , n ) ; return 0 ; }

Index/key variables: MAX_CHAR, i, ind
Accumulator variables: i, stdc
Iterator variables: i
Class/struct names: Trie