dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int CountPairs ( int arr [ ] , int n ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( arr [ i ] + arr [ j ] > 0 ) count += 1 ; } } return count ; } int main ( ) { int arr [ ] = { -7 , -1 , 3 , 2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << CountPairs ( arr , n ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: count, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
#define MAX  100001
using namespace std ; typedef struct { int l , r , v ; } interval ; bool cmp ( interval a , interval b ) { return a . v < b . v ; } bool isPossible ( int range [ ] [ 3 ] , int N ) { interval test [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { test [ i ] . l = range [ i ] [ 0 ] ; test [ i ] . r = range [ i ] [ 1 ] ; test [ i ] . v = range [ i ] [ 2 ] ; } sort ( test , test + N , cmp ) ; for ( int i = 0 ; i < N ; i ++ ) { int count [ MAX ] = { 0 } ; int current_velocity = test [ i ] . v ; int j = i ; while ( j < N && test [ j ] . v == current_velocity ) { for ( int k = test [ j ] . l ; k <= test [ j ] . r ; k ++ ) { count [ k ] ++ ; if ( count [ k ] >= 3 ) return false ; } j ++ ; } i = j - 1 ; } return true ; } int main ( ) { int range [ ] [ 3 ] = { { 1 , 2 , 3 } , { 2 , 5 , 1 } , { 3 , 10 , 1 } , { 4 , 4 , 1 } , { 5 , 7 , 10 } } ; int n = sizeof ( range ) / sizeof ( range [ 0 ] ) ; if ( isPossible ( range , n ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Index/key variables: MAX, N, i, j, k
Accumulator variables: i, j, k, stdc
Iterator variables: i, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define int  long long
const int N = 2005 ; set < int > ans ; void dfs ( int num , int left , int ct ) { if ( ct >= 15 ) return ; if ( left == 0 ) ans . insert ( num ) ; for ( int i = 0 ; i <= min ( left , 9LL ) ; i ++ ) dfs ( num * 10 + i , left - i , ct + 1 ) ; } int getKthNum ( int m , int k ) { dfs ( 0 , m , 0 ) ; int ct = 0 ; for ( auto it : ans ) { ct ++ ; if ( ct == k ) { return it ; } } return -1 ; } int main ( ) { int m = 5 , k = 3 ; cout << getKthNum ( m , k ) ; return 0 ; }

Accumulator variables: ct, i, stdc
Iterator variables: i, it
C++ program:
#include <bits/stdc++.h>
using namespace std ; int Removal ( vector < int > v , int n ) { sort ( v . begin ( ) , v . end ( ) ) ; int ans = INT_MAX ; for ( vector < int > :: iterator i = v . begin ( ) ; i != v . end ( ) ; i ++ ) { vector < int > :: iterator j = upper_bound ( v . begin ( ) , v . end ( ) , ( 2 * ( * i ) ) ) ; ans = min ( ans , n - ( int ) ( j - i ) ) ; } return ans ; } int main ( ) { vector < int > a = { 4 , 5 , 100 , 9 , 10 , 11 , 12 , 15 , 200 } ; int n = a . size ( ) ; cout << Removal ( a , n ) ; return 0 ; }

Accumulator variables: i, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void FrontToLast ( queue < int > & q , int qsize ) { if ( qsize <= 0 ) return ; q . push ( q . front ( ) ) ; q . pop ( ) ; FrontToLast ( q , qsize - 1 ) ; } void pushInQueue ( queue < int > & q , int temp , int qsize ) { if ( q . empty ( ) qsize == 0 ) { q . push ( temp ) ; return ; } else if ( temp <= q . front ( ) ) { q . push ( temp ) ; FrontToLast ( q , qsize ) ; } else { q . push ( q . front ( ) ) ; q . pop ( ) ; pushInQueue ( q , temp , qsize - 1 ) ; } } void sortQueue ( queue < int > & q ) { if ( q . empty ( ) ) return ; int temp = q . front ( ) ; q . pop ( ) ; sortQueue ( q ) ; pushInQueue ( q , temp , q . size ( ) ) ; } int main ( ) { queue < int > qu ; qu . push ( 10 ) ; qu . push ( 7 ) ; qu . push ( 16 ) ; qu . push ( 9 ) ; qu . push ( 20 ) ; qu . push ( 5 ) ; sortQueue ( qu ) ; while ( ! qu . empty ( ) ) { cout << qu . front ( ) << " ▁ " ; qu . pop ( ) ; } }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void swap ( char * a , char * b ) { char t = * a ; * a = * b ; * b = t ; } int partition ( char arr [ ] , int low , int high , int mod ) { char pivot = arr [ high ] ; int i = ( low - 1 ) ; int piv = pivot % mod ; for ( int j = low ; j <= high - 1 ; j ++ ) { int a = arr [ j ] % mod ; if ( a <= piv ) { i ++ ; swap ( & arr [ i ] , & arr [ j ] ) ; } } swap ( & arr [ i + 1 ] , & arr [ high ] ) ; return ( i + 1 ) ; } void quickSort ( char arr [ ] , int low , int high , int mod ) { if ( low < high ) { int pi = partition ( arr , low , high , mod ) ; quickSort ( arr , low , pi - 1 , mod ) ; quickSort ( arr , pi + 1 , high , mod ) ; } } void printArray ( char arr [ ] , int size ) { for ( int i = 0 ; i < size ; i ++ ) cout << arr [ i ] << " ▁ " ; } int main ( ) { char arr [ ] = { ' g ' , ' e ' , ' e ' , ' k ' , ' s ' } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int mod = 8 ; quickSort ( arr , 0 , n - 1 , mod ) ; printArray ( arr , n ) ; return 0 ; }

Index/key variables: high, i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct node { int data ; struct node * left , * right ; node ( int x ) { data = x ; left = right = NULL ; } } ; void insertionSort ( vector < int > & v , int n ) { int i , key , j ; for ( i = 1 ; i < n ; i ++ ) { key = v [ i ] ; j = i - 1 ; while ( j >= 0 && v [ j ] > key ) { v [ j + 1 ] = v [ j ] ; j = j - 1 ; } v [ j + 1 ] = key ; } } void inorder ( node * root , vector < int > & v ) { if ( ! root ) return ; inorder ( root -> left , v ) ; v . push_back ( root -> data ) ; inorder ( root -> right , v ) ; } void find ( node * root , int res , int res2 ) { if ( ! root ) { return ; } find ( root -> left , res , res2 ) ; if ( root -> data == res ) { root -> data = res2 ; } else if ( root -> data == res2 ) { root -> data = res ; } find ( root -> right , res , res2 ) ; } struct node * correctBST ( struct node * root ) { vector < int > v ; inorder ( root , v ) ; vector < int > v1 = v ; insertionSort ( v , v . size ( ) ) ; for ( int i = 0 ; i < v . size ( ) ; i ++ ) { if ( v [ i ] != v1 [ i ] ) { find ( root , v1 [ i ] , v [ i ] ) ; break ; } } return root ; } void printInorder ( struct node * node ) { if ( node == NULL ) return ; printInorder ( node -> left ) ; printf ( " % d ▁ " , node -> data ) ; printInorder ( node -> right ) ; } int main ( ) { struct node * root = new node ( 6 ) ; root -> left = new node ( 10 ) ; root -> right = new node ( 2 ) ; root -> left -> left = new node ( 1 ) ; root -> left -> right = new node ( 3 ) ; root -> right -> right = new node ( 12 ) ; root -> right -> left = new node ( 7 ) ; printf ( " Inorder ▁ Traversal ▁ of ▁ the " ) ; printf ( " original ▁ tree ▁ STRNEWLINE " ) ; printInorder ( root ) ; correctBST ( root ) ; printf ( " Inorder Traversal of the " printf ( " fixed ▁ tree ▁ STRNEWLINE " ) ; printInorder ( root ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, stdc
Iterator variables: i
Class/struct names: node
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; Node * next ; } ; Node * newNode ( int val ) { Node * temp = new Node ; temp -> data = val ; temp -> next = NULL ; return temp ; } Node * selectionSort ( Node * head ) { Node * a , * b , * c , * d , * r ; a = b = head ; while ( b -> next ) { c = d = b -> next ; while ( d ) { if ( b -> data > d -> data ) { if ( b -> next == d ) { if ( b == head ) { b -> next = d -> next ; d -> next = b ; r = b ; b = d ; d = r ; c = d ; head = b ; d = d -> next ; } else { b -> next = d -> next ; d -> next = b ; a -> next = d ; r = b ; b = d ; d = r ; c = d ; d = d -> next ; } } else { if ( b == head ) { r = b -> next ; b -> next = d -> next ; d -> next = r ; c -> next = b ; r = b ; b = d ; d = r ; c = d ; d = d -> next ; head = b ; } else { r = b -> next ; b -> next = d -> next ; d -> next = r ; c -> next = b ; a -> next = d ; r = b ; b = d ; d = r ; c = d ; d = d -> next ; } } } else { c = d ; d = d -> next ; } } a = b ; b = b -> next ; } return head ; } void printList ( Node * head ) { while ( head ) { cout << head -> data << " ▁ " ; head = head -> next ; } } int main ( ) { Node * head = newNode ( 5 ) ; head -> next = newNode ( 4 ) ; head -> next -> next = newNode ( 3 ) ; head = selectionSort ( head ) ; printList ( head ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printArr ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) cout << arr [ i ] << " ▁ " ; } void findNumbers ( int arr [ ] , int n ) { sort ( arr , arr + n , greater < int > ( ) ) ; int freq [ arr [ 0 ] + 1 ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) freq [ arr [ i ] ] ++ ; int size = sqrt ( n ) ; int brr [ size ] = { 0 } , x , l = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( freq [ arr [ i ] ] > 0 ) { brr [ l ] = arr [ i ] ; freq [ brr [ l ] ] -- ; l ++ ; for ( int j = 0 ; j < l ; j ++ ) { if ( i != j ) { x = __gcd ( arr [ i ] , brr [ j ] ) ; freq [ x ] -= 2 ; } } } } printArr ( brr , size ) ; } int main ( ) { int arr [ ] = { 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 5 , 5 , 5 , 7 , 10 , 12 , 2 , 2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; findNumbers ( arr , n ) ; return 0 ; }

Index/key variables: i, j, l, size, x
Accumulator variables: i, j, l, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; string strBitwiseAND ( string * arr , int n ) { string res ; int smallest_size = INT_MAX ; int largest_size = INT_MIN ; for ( int i = 0 ; i < n ; i ++ ) { reverse ( arr [ i ] . begin ( ) , arr [ i ] . end ( ) ) ; smallest_size = min ( smallest_size , ( int ) arr [ i ] . size ( ) ) ; largest_size = max ( largest_size , ( int ) arr [ i ] . size ( ) ) ; } for ( int i = 0 ; i < smallest_size ; i ++ ) { bool all_ones = true ; for ( int j = 0 ; j < n ; j ++ ) { if ( arr [ j ] [ i ] == '0' ) { all_ones = false ; break ; } } res += ( all_ones ? '1' : '0' ) ; } for ( int i = 0 ; i < largest_size - smallest_size ; i ++ ) res += '0' ; reverse ( res . begin ( ) , res . end ( ) ) ; return res ; } int main ( ) { string arr [ ] = { "101" , "110110" , "111" } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << strBitwiseAND ( arr , n ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, res, stdc
Iterator variables: i, j
Boolean variables: all_ones
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printpath ( vector < int > & path ) { int size = path . size ( ) ; for ( int i = 0 ; i < size ; i ++ ) cout << path [ i ] << " ▁ " ; cout << endl ; } int isNotVisited ( int x , vector < int > & path ) { int size = path . size ( ) ; for ( int i = 0 ; i < size ; i ++ ) if ( path [ i ] == x ) return 0 ; return 1 ; } void findpaths ( vector < vector < int > > & g , int src , int dst , int v ) { queue < vector < int > > q ; vector < int > path ; path . push_back ( src ) ; q . push ( path ) ; while ( ! q . empty ( ) ) { path = q . front ( ) ; q . pop ( ) ; int last = path [ path . size ( ) - 1 ] ; if ( last == dst ) printpath ( path ) ; for ( int i = 0 ; i < g [ last ] . size ( ) ; i ++ ) { if ( isNotVisited ( g [ last ] [ i ] , path ) ) { vector < int > newpath ( path ) ; newpath . push_back ( g [ last ] [ i ] ) ; q . push ( newpath ) ; } } } } int main ( ) { vector < vector < int > > g ; int v = 4 ; g . resize ( 4 ) ; g [ 0 ] . push_back ( 3 ) ; g [ 0 ] . push_back ( 1 ) ; g [ 0 ] . push_back ( 2 ) ; g [ 1 ] . push_back ( 3 ) ; g [ 2 ] . push_back ( 0 ) ; g [ 2 ] . push_back ( 1 ) ; int src = 2 , dst = 3 ; cout << " path ▁ from ▁ src ▁ " << src << " ▁ to ▁ dst ▁ " << dst << " ▁ are ▁ STRNEWLINE " ; findpaths ( g , src , dst , v ) ; return 0 ; }

Index/key variables: i, last
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void AlternateRearrange ( int arr [ ] , int n ) { sort ( arr , arr + n ) ; for ( int i = 0 ; i < n ; i ++ ) if ( arr [ i ] % 2 == 0 ) v1 . push_back ( arr [ i ] ) ; else v2 . push_back ( arr [ i ] ) ; int index = 0 , i = 0 , j = 0 ; bool flag = false ; if ( arr [ 0 ] % 2 == 0 ) flag = true ; while ( index < n ) { if ( flag == true ) { arr [ index ++ ] = v1 [ i ++ ] ; flag = ! flag ; } else { arr [ index ++ ] = v2 [ j ++ ] ; flag = ! flag ; } } for ( i = 0 ; i < n ; i ++ ) cout << arr [ i ] << " ▁ " ; } int main ( ) { int arr [ ] = { 9 , 8 , 13 , 2 , 19 , 14 } ; int n = sizeof ( arr ) / sizeof ( int ) ; AlternateRearrange ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, index, j, stdc
Iterator variables: i
Boolean variables: flag
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getNumToAdd ( int arr [ ] , int n ) { sort ( arr , arr + n ) ; int d = arr [ 1 ] - arr [ 0 ] ; int numToAdd = -1 ; bool numAdded = false ; for ( int i = 2 ; i < n ; i ++ ) { int diff = arr [ i ] - arr [ i - 1 ] ; if ( diff != d ) { if ( numAdded ) return -1 ; if ( diff == 2 * d ) { numToAdd = arr [ i ] - d ; numAdded = true ; } else return -1 ; } } if ( numToAdd == -1 ) return ( arr [ n - 1 ] + d ) ; return numToAdd ; } int main ( ) { int arr [ ] = { 1 , 3 , 5 , 7 , 11 , 13 , 15 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << getNumToAdd ( arr , n ) ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
Boolean variables: numAdded
C++ program:
#include <bits/stdc++.h>
using namespace std ; int Minimum_Cells ( vector < pair < int , int > > v ) { int col [ 3 ] , i , j ; for ( i = 0 ; i < 3 ; i ++ ) { int column_number = v [ i ] . second ; col [ i ] = column_number ; } sort ( col , col + 3 ) ; sort ( v . begin ( ) , v . end ( ) ) ; int MidRow = v [ 1 ] . first ; set < pair < int , int > > s ; int Maxcol = col [ 2 ] , MinCol = col [ 0 ] ; for ( i = MinCol ; i <= Maxcol ; i ++ ) { s . insert ( { MidRow , i } ) ; } for ( i = 0 ; i < 3 ; i ++ ) { if ( v [ i ] . first == MidRow ) continue ; for ( j = min ( v [ i ] . first , MidRow ) ; j <= max ( v [ i ] . first , MidRow ) ; j ++ ) { s . insert ( { j , v [ i ] . second } ) ; } } return s . size ( ) ; } int main ( ) { vector < pair < int , int > > v = { { 0 , 0 } , { 1 , 1 } , { 2 , 2 } } ; cout << Minimum_Cells ( v ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int items ( int n , int a [ ] ) { sort ( a , a + n ) ; int z = a [ n - 1 ] ; int x = 1 ; int s = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { s += a [ i ] ; if ( s <= z ) x += 1 ; else break ; } return x ; } int main ( ) { int n = 5 ; int a [ ] = { 5 , 3 , 1 , 5 , 6 } ; cout << items ( n , a ) ; }

Index/key variables: i
Accumulator variables: i, s, stdc, x
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void sortWithSetbits ( int arr [ ] , int n , int k ) { vector < int > v1 , v2 ; for ( int i = 0 ; i < n ; i ++ ) { if ( __builtin_popcount ( arr [ i ] ) == k ) { v1 . push_back ( i ) ; v2 . push_back ( arr [ i ] ) ; } } sort ( v2 . begin ( ) , v2 . end ( ) ) ; for ( int i = 0 ; i < v1 . size ( ) ; i ++ ) arr [ v1 [ i ] ] = v2 [ i ] ; for ( int i = 0 ; i < n ; i ++ ) cout << arr [ i ] << " ▁ " ; } int main ( ) { int arr [ ] = { 14 , 255 , 1 , 7 , 13 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 3 ; sortWithSetbits ( arr , n , k ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int numBoxes ( int A [ ] , int n , int K ) { sort ( A , A + n ) ; int i = 0 , j = n - 1 ; int ans = 0 ; while ( i <= j ) { ans ++ ; if ( A [ i ] + A [ j ] <= K ) i ++ ; j -- ; } return ans ; } int main ( ) { int A [ ] = { 3 , 2 , 2 , 1 } , K = 3 ; int n = sizeof ( A ) / sizeof ( A [ 0 ] ) ; cout << numBoxes ( A , n , K ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: ans, i, j, stdc
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 * ptr , * ptr1 , * ptr2 ; int count = 0 ; unordered_map < int , Node * > um ; for ( ptr = head ; ptr != NULL ; ptr = ptr -> next ) um [ ptr -> data ] = ptr ; for ( ptr1 = head ; ptr1 != NULL ; ptr1 = ptr1 -> next ) for ( ptr2 = ptr1 -> next ; ptr2 != NULL ; ptr2 = ptr2 -> next ) { int p_product = ( ptr1 -> data * ptr2 -> data ) ; if ( um . find ( x / p_product ) != um . end ( ) && um [ x / p_product ] != ptr1 && um [ x / p_product ] != ptr2 ) count ++ ; } return ( count / 3 ) ; } 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: ptr, ptr1, ptr2
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int solve ( int N , int M , int cp [ ] , int sp [ ] ) { int profit [ N ] ; for ( int i = 0 ; i < N ; i ++ ) profit [ i ] = sp [ i ] - cp [ i ] ; sort ( profit , profit + N , greater < int > ( ) ) ; int sum = 0 ; for ( int i = 0 ; i < M ; i ++ ) { if ( profit [ i ] > 0 ) sum += profit [ i ] ; else break ; } return sum ; } int main ( ) { int N = 5 , M = 3 ; int CP [ ] = { 5 , 10 , 35 , 7 , 23 } ; int SP [ ] = { 11 , 10 , 0 , 9 , 19 } ; cout << solve ( N , M , CP , SP ) ; return 0 ; }

Index/key variables: N, i
Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findMaxNum ( int arr [ ] , int n ) { sort ( arr , arr + n , greater < int > ( ) ) ; int num = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { num = num * 10 + arr [ i ] ; } return num ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 0 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findMaxNum ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <algorithm>
#include <iostream>
using namespace std ; int minimumSets ( int arr [ ] , int n , int key ) { int i , j ; sort ( arr , arr + n ) ; for ( i = 0 , j = n - 1 ; i <= j ; ++ i ) if ( arr [ i ] + arr [ j ] <= key ) j -- ; return i ; } int main ( ) { int arr [ ] = { 3 , 5 , 3 , 4 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int key = 5 ; cout << minimumSets ( arr , n , key ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: j
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; struct Node { int data ; Node * prev ; Node * next ; } ; void insertAtTheBegin ( struct Node * * start_ref , int data ) { struct Node * ptr1 = new Node ; ptr1 -> data = data ; ptr1 -> next = * start_ref ; if ( * start_ref != NULL ) ( * start_ref ) -> prev = ptr1 ; * start_ref = ptr1 ; } void printList ( struct Node * start ) { struct Node * temp = start ; cout << endl ; while ( temp != NULL ) { cout << temp -> data << " ▁ " ; temp = temp -> next ; } } void bubbleSort ( struct Node * start ) { int swapped , i ; struct Node * ptr1 ; struct Node * lptr = NULL ; if ( start == NULL ) return ; do { swapped = 0 ; ptr1 = start ; while ( ptr1 -> next != lptr ) { if ( ptr1 -> data > ptr1 -> next -> data ) { swap ( ptr1 -> data , ptr1 -> next -> data ) ; swapped = 1 ; } ptr1 = ptr1 -> next ; } lptr = ptr1 ; } while ( swapped ) ; } int main ( ) { int arr [ ] = { 12 , 56 , 2 , 11 , 1 , 90 } ; int list_size , i ; struct Node * start = NULL ; for ( i = 0 ; i < 6 ; i ++ ) insertAtTheBegin ( & start , arr [ i ] ) ; printf ( " Linked list before sorting " printList ( start ) ; bubbleSort ( start ) ; printf ( " Linked list after sorting " printList ( start ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; void substringSort ( string arr [ ] , int n , int maxLen ) { int count [ maxLen ] ; string sortedArr [ maxLen ] ; for ( int i = 0 ; i < maxLen ; i ++ ) { count [ i ] = 0 ; sortedArr [ i ] = " " ; } for ( int i = 0 ; i < n ; i ++ ) { string s = arr [ i ] ; int len = s . length ( ) ; if ( count [ len - 1 ] == 0 ) { sortedArr [ len - 1 ] = s ; count [ len - 1 ] = 1 ; } else if ( sortedArr [ len - 1 ] == s ) { count [ len - 1 ] ++ ; } else { cout << " Cannot ▁ be ▁ sorted " ; return ; } } int index = 0 ; while ( count [ index ] == 0 ) index ++ ; int prev = index ; string prevString = sortedArr [ prev ] ; index ++ ; for ( ; index < maxLen ; index ++ ) { if ( count [ index ] != 0 ) { string current = sortedArr [ index ] ; if ( current . find ( prevString ) != string :: npos ) { prev = index ; prevString = current ; } else { cout << " Cannot ▁ be ▁ sorted " ; return ; } } } for ( int i = 0 ; i < maxLen ; i ++ ) { string s = sortedArr [ i ] ; for ( int j = 0 ; j < count [ i ] ; j ++ ) { cout << s << endl ; } } } int main ( ) { int maxLen = 100 ; string arr1 [ ] = { " d " , " zddsaaz " , " ds " , " ddsaa " , " dds " , " dds " } ; substringSort ( arr1 , sizeof ( arr1 ) / sizeof ( arr1 [ 0 ] ) , maxLen ) ; string arr2 [ ] = { " for " , " rof " } ; substringSort ( arr2 , sizeof ( arr2 ) / sizeof ( arr2 [ 0 ] ) , maxLen ) ; return 0 ; }

Index/key variables: i, index, maxLen, prev
Accumulator variables: i, index, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAXN  1000005
vector < int > v [ MAXN ] ; void add_edge ( int a , int b , int fre [ ] ) { v [ a ] . push_back ( b ) ; fre [ b ] ++ ; } vector < int > topological_sorting ( int fre [ ] , int n ) { queue < int > q ; for ( int i = 0 ; i < n ; i ++ ) if ( ! fre [ i ] ) q . push ( i ) ; vector < int > l ; while ( ! q . empty ( ) ) { int u = q . front ( ) ; q . pop ( ) ; l . push_back ( u ) ; for ( int i = 0 ; i < v [ u ] . size ( ) ; i ++ ) { fre [ v [ u ] [ i ] ] -- ; if ( ! fre [ v [ u ] [ i ] ] ) q . push ( v [ u ] [ i ] ) ; } } return l ; } int numberofPaths ( int source , int destination , int n , int fre [ ] ) { vector < int > s = topological_sorting ( fre , n ) ; int dp [ n ] = { 0 } ; dp [ destination ] = 1 ; for ( int i = s . size ( ) - 1 ; i >= 0 ; i -- ) { for ( int j = 0 ; j < v [ s [ i ] ] . size ( ) ; j ++ ) { dp [ s [ i ] ] += dp [ v [ s [ i ] ] [ j ] ] ; } } return dp ; } int main ( ) { int n = 5 ; int source = 0 , destination = 4 ; int fre [ n ] = { 0 } ; add_edge ( 0 , 1 , fre ) ; add_edge ( 0 , 2 , fre ) ; add_edge ( 0 , 3 , fre ) ; add_edge ( 0 , 4 , fre ) ; add_edge ( 2 , 3 , fre ) ; add_edge ( 3 , 4 , fre ) ; cout << numberofPaths ( source , destination , n , fre ) ; }

Index/key variables: MAXN, a, b, destination, i, j, n, u
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printPairs ( int arr [ ] , int n ) { bool pair_exists = false ; sort ( arr , arr + n ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] < 0 ) { if ( binary_search ( arr , arr + n , - arr [ i ] ) ) { cout << arr [ i ] << " , ▁ " << - arr [ i ] << endl ; pair_exists = true ; } } else break ; } if ( pair_exists == false ) cout << " No ▁ such ▁ pair ▁ exists " ; } int main ( ) { int arr [ ] = { 4 , 8 , 9 , -4 , 1 , -1 , -8 , -9 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; printPairs ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
Boolean variables: pair_exists
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool areSame ( vector < int > & a , vector < int > & b ) { sort ( a . begin ( ) , a . end ( ) ) ; sort ( b . begin ( ) , b . end ( ) ) ; return ( a == b ) ; } int main ( ) { vector < int > a ( { 7 , 7 , 5 } ) , b ( { 7 , 5 , 5 } ) ; if ( areSame ( a , b ) ) cout << " Yes STRNEWLINE " ; else cout << " No STRNEWLINE " ; return 0 ; }

Accumulator variables: stdc