dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; Node * prev , * next ; static Node * getnode ( int data ) { Node * newNode = ( Node * ) malloc ( sizeof ( Node ) ) ; newNode -> data = data ; newNode -> prev = newNode -> next = NULL ; return newNode ; } } ; class Deque { Node * front ; Node * rear ; int Size ; public : Deque ( ) { front = rear = NULL ; Size = 0 ; } void insertFront ( int data ) ; void insertRear ( int data ) ; void deleteFront ( ) ; void deleteRear ( ) ; int getFront ( ) ; int getRear ( ) ; int size ( ) ; bool isEmpty ( ) ; void erase ( ) ; } ; bool Deque :: isEmpty ( ) { return ( front == NULL ) ; } int Deque :: size ( ) { return Size ; } void Deque :: insertFront ( int data ) { Node * newNode = Node :: getnode ( data ) ; if ( newNode == NULL ) cout << " OverFlow STRNEWLINE " ; else { if ( front == NULL ) rear = front = newNode ; else { newNode -> next = front ; front -> prev = newNode ; front = newNode ; } Size ++ ; } } void Deque :: insertRear ( int data ) { Node * newNode = Node :: getnode ( data ) ; if ( newNode == NULL ) cout << " OverFlow STRNEWLINE " ; else { if ( rear == NULL ) front = rear = newNode ; else { newNode -> prev = rear ; rear -> next = newNode ; rear = newNode ; } Size ++ ; } } void Deque :: deleteFront ( ) { if ( isEmpty ( ) ) cout << " UnderFlow STRNEWLINE " ; else { Node * temp = front ; front = front -> next ; if ( front == NULL ) rear = NULL ; else front -> prev = NULL ; free ( temp ) ; Size -- ; } } void Deque :: deleteRear ( ) { if ( isEmpty ( ) ) cout << " UnderFlow STRNEWLINE " ; else { Node * temp = rear ; rear = rear -> prev ; if ( rear == NULL ) front = NULL ; else rear -> next = NULL ; free ( temp ) ; Size -- ; } } int Deque :: getFront ( ) { if ( isEmpty ( ) ) return -1 ; return front -> data ; } int Deque :: getRear ( ) { if ( isEmpty ( ) ) return -1 ; return rear -> data ; } void Deque :: erase ( ) { rear = NULL ; while ( front != NULL ) { Node * temp = front ; front = front -> next ; free ( temp ) ; } Size = 0 ; } int main ( ) { Deque dq ; cout << " Insert ▁ element ▁ ' 5 ' ▁ at ▁ rear ▁ end STRNEWLINE " ; dq . insertRear ( 5 ) ; cout << " Insert ▁ element ▁ ' 10 ' ▁ at ▁ rear ▁ end STRNEWLINE " ; dq . insertRear ( 10 ) ; cout << " Rear ▁ end ▁ element : ▁ " << dq . getRear ( ) << endl ; dq . deleteRear ( ) ; cout << " After ▁ deleting ▁ rear ▁ element ▁ new ▁ rear " << " ▁ is : ▁ " << dq . getRear ( ) << endl ; cout << " Inserting ▁ element ▁ ' 15 ' ▁ at ▁ front ▁ end ▁ STRNEWLINE " ; dq . insertFront ( 15 ) ; cout << " Front ▁ end ▁ element : ▁ " << dq . getFront ( ) << endl ; cout << " Number ▁ of ▁ elements ▁ in ▁ Deque : ▁ " << dq . size ( ) << endl ; dq . deleteFront ( ) ; cout << " After ▁ deleting ▁ front ▁ element ▁ new ▁ " << " front ▁ is : ▁ " << dq . getFront ( ) << endl ; return 0 ; }

Accumulator variables: Size, stdc
Class/struct names: Deque, Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; struct Node * newNode ( int data ) { struct Node * node = ( struct Node * ) malloc ( sizeof ( struct Node ) ) ; node -> data = data ; node -> left = node -> right = NULL ; return node ; } bool checkUtil ( struct Node * root , int level , int * leafLevel ) { if ( root == NULL ) return true ; if ( root -> left == NULL && root -> right == NULL ) { if ( * leafLevel == 0 ) { * leafLevel = level ; return true ; } return ( level == * leafLevel ) ; } return checkUtil ( root -> left , level + 1 , leafLevel ) && checkUtil ( root -> right , level + 1 , leafLevel ) ; } bool check ( struct Node * root ) { int level = 0 , leafLevel = 0 ; return checkUtil ( root , level , & leafLevel ) ; } int main ( ) { struct Node * root = newNode ( 12 ) ; root -> left = newNode ( 5 ) ; root -> left -> left = newNode ( 3 ) ; root -> left -> right = newNode ( 9 ) ; root -> left -> left -> left = newNode ( 1 ) ; root -> left -> right -> left = newNode ( 1 ) ; if ( check ( root ) ) cout << " Leaves ▁ are ▁ at ▁ same ▁ level STRNEWLINE " ; else cout << " Leaves ▁ are ▁ not ▁ at ▁ same ▁ level STRNEWLINE " ; getchar ( ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; class Node { public : int key ; vector < Node * > child ; Node ( int data ) { key = data ; } } ; int numberOfSiblings ( Node * root , int x ) { if ( root == NULL ) return 0 ; queue < Node * > q ; q . push ( root ) ; while ( ! q . empty ( ) ) { Node * p = q . front ( ) ; q . pop ( ) ; for ( int i = 0 ; i < p -> child . size ( ) ; i ++ ) { if ( p -> child [ i ] -> key == x ) return p -> child . size ( ) - 1 ; q . push ( p -> child [ i ] ) ; } } } int main ( ) { Node * root = new Node ( 50 ) ; ( root -> child ) . push_back ( new Node ( 2 ) ) ; ( root -> child ) . push_back ( new Node ( 30 ) ) ; ( root -> child ) . push_back ( new Node ( 14 ) ) ; ( root -> child ) . push_back ( new Node ( 60 ) ) ; ( root -> child [ 0 ] -> child ) . push_back ( new Node ( 15 ) ) ; ( root -> child [ 0 ] -> child ) . push_back ( new Node ( 25 ) ) ; ( root -> child [ 0 ] -> child [ 1 ] -> child ) . push_back ( new Node ( 70 ) ) ; ( root -> child [ 0 ] -> child [ 1 ] -> child ) . push_back ( new Node ( 100 ) ) ; ( root -> child [ 1 ] -> child ) . push_back ( new Node ( 6 ) ) ; ( root -> child [ 1 ] -> child ) . push_back ( new Node ( 1 ) ) ; ( root -> child [ 2 ] -> child ) . push_back ( new Node ( 7 ) ) ; ( root -> child [ 2 ] -> child [ 0 ] -> child ) . push_back ( new Node ( 17 ) ) ; ( root -> child [ 2 ] -> child [ 0 ] -> child ) . push_back ( new Node ( 99 ) ) ; ( root -> child [ 2 ] -> child [ 0 ] -> child ) . push_back ( new Node ( 27 ) ) ; ( root -> child [ 3 ] -> child ) . push_back ( new Node ( 16 ) ) ; int x = 100 ; cout << numberOfSiblings ( root , x ) << endl ; return 0 ; }

Index/key variables: i
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 * left , * right ; } ; Node * newNode ( int data ) { Node * temp = new Node ( ) ; temp -> data = data ; temp -> left = temp -> right = NULL ; return temp ; } int checkLevelLeafNode ( Node * root ) { if ( ! root ) return 1 ; queue < Node * > q ; q . push ( root ) ; int result = INT_MAX ; int level = 0 ; while ( ! q . empty ( ) ) { int size = q . size ( ) ; level += 1 ; while ( size > 0 ) { Node * temp = q . front ( ) ; q . pop ( ) ; if ( temp -> left ) { q . push ( temp -> left ) ; if ( ! temp -> left -> right && ! temp -> left -> left ) { if ( result == INT_MAX ) result = level ; else if ( result != level ) return 0 ; } } if ( temp -> right ) { q . push ( temp -> right ) ; if ( ! temp -> right -> left && ! temp -> right -> right ) if ( result == INT_MAX ) result = level ; else if ( result != level ) return 0 ; } size -= 1 ; } } return 1 ; } int main ( ) { Node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; root -> left -> right = newNode ( 4 ) ; root -> right -> left = newNode ( 5 ) ; root -> right -> right = newNode ( 6 ) ; int result = checkLevelLeafNode ( root ) ; if ( result ) cout << " All ▁ leaf ▁ nodes ▁ are ▁ at ▁ same ▁ level STRNEWLINE " ; else cout << " Leaf ▁ nodes ▁ not ▁ at ▁ same ▁ level STRNEWLINE " ; return 0 ; }

Accumulator variables: level, size, stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; void print_queue ( queue < int > q ) { while ( ! q . empty ( ) ) { cout << q . front ( ) << " ▁ " ; q . pop ( ) ; } cout << endl ; } int main ( ) { queue < int > q ; for ( int i = 0 ; i < 5 ; i ++ ) q . push ( i ) ; cout << " Elements ▁ of ▁ queue - " ; print_queue ( q ) ; int removedele = q . front ( ) ; q . pop ( ) ; cout << " removed ▁ element - " << removedele << endl ; print_queue ( q ) ; int head = q . front ( ) ; cout << " head ▁ of ▁ queue - " << head << endl ; int size = q . size ( ) ; cout << " Size ▁ of ▁ queue - " << size ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; stack < int > stack_push ( stack < int > stack ) { for ( int i = 0 ; i < 5 ; i ++ ) { stack . push ( i ) ; } return stack ; } stack < int > stack_pop ( stack < int > stack ) { cout << " Pop ▁ : " ; for ( int i = 0 ; i < 5 ; i ++ ) { int y = ( int ) stack . top ( ) ; stack . pop ( ) ; cout << ( y ) << endl ; } return stack ; } void stack_peek ( stack < int > stack ) { int element = ( int ) stack . top ( ) ; cout << " Element ▁ on ▁ stack ▁ top ▁ : ▁ " << element << endl ; } void stack_search ( stack < int > stack , int element ) { int pos = -1 , co = 0 ; while ( stack . size ( ) > 0 ) { co ++ ; if ( stack . top ( ) == element ) { pos = co ; break ; } stack . pop ( ) ; } if ( pos == -1 ) cout << " Element ▁ not ▁ found " << endl ; else cout << " Element ▁ is ▁ found ▁ at ▁ position ▁ " << pos << endl ; } int main ( ) { stack < int > stack ; stack = stack_push ( stack ) ; stack = stack_pop ( stack ) ; stack = stack_push ( stack ) ; stack_peek ( stack ) ; stack_search ( stack , 2 ) ; stack_search ( stack , 6 ) ; return 0 ; }

Accumulator variables: co, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printQueue ( queue < long long int > Queue ) { while ( ! Queue . empty ( ) ) { cout << Queue . front ( ) << " ▁ " ; Queue . pop ( ) ; } } void reverseQueue ( queue < long long int > & q ) { if ( q . empty ( ) ) return ; long long int data = q . front ( ) ; q . pop ( ) ; reverseQueue ( q ) ; q . push ( data ) ; } int main ( ) { queue < long long int > Queue ; Queue . push ( 56 ) ; Queue . push ( 27 ) ; Queue . push ( 30 ) ; Queue . push ( 45 ) ; Queue . push ( 85 ) ; Queue . push ( 92 ) ; Queue . push ( 58 ) ; Queue . push ( 80 ) ; Queue . push ( 90 ) ; Queue . push ( 100 ) ; reverseQueue ( Queue ) ; printQueue ( Queue ) ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minIndex ( queue < int > & q , int sortedIndex ) { int min_index = -1 ; int min_val = INT_MAX ; int n = q . size ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int curr = q . front ( ) ; q . pop ( ) ; if ( curr <= min_val && i <= sortedIndex ) { min_index = i ; min_val = curr ; } q . push ( curr ) ; } return min_index ; } void insertMinToRear ( queue < int > & q , int min_index ) { int min_val ; int n = q . size ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int curr = q . front ( ) ; q . pop ( ) ; if ( i != min_index ) q . push ( curr ) ; else min_val = curr ; } q . push ( min_val ) ; } void sortQueue ( queue < int > & q ) { for ( int i = 1 ; i <= q . size ( ) ; i ++ ) { int min_index = minIndex ( q , q . size ( ) - i ) ; insertMinToRear ( q , min_index ) ; } } int main ( ) { queue < int > q ; q . push ( 30 ) ; q . push ( 11 ) ; q . push ( 15 ) ; q . push ( 4 ) ; sortQueue ( q ) ; while ( q . empty ( ) == false ) { cout << q . front ( ) << " ▁ " ; q . pop ( ) ; } cout << endl ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; struct Node * newNode ( int x ) { struct Node * temp = new Node ; temp -> data = x ; temp -> left = temp -> right = NULL ; return temp ; } ; int count ( Node * root ) { if ( root == NULL ) return 0 ; return count ( root -> left ) + count ( root -> right ) + 1 ; } bool checkRec ( Node * root , int n ) { if ( root == NULL ) return false ; if ( count ( root ) == n - count ( root ) ) return true ; return checkRec ( root -> left , n ) || checkRec ( root -> right , n ) ; } bool check ( Node * root ) { int n = count ( root ) ; return checkRec ( root , n ) ; } int main ( ) { struct Node * root = newNode ( 5 ) ; root -> left = newNode ( 1 ) ; root -> right = newNode ( 6 ) ; root -> left -> left = newNode ( 3 ) ; root -> right -> left = newNode ( 7 ) ; root -> right -> right = newNode ( 4 ) ; check ( root ) ? printf ( " YES " ) : printf ( " NO " ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printKMax ( int arr [ ] , int n , int k ) { std :: deque < int > Qi ( k ) ; int i ; for ( i = 0 ; i < k ; ++ i ) { while ( ( ! Qi . empty ( ) ) && arr [ i ] >= arr [ Qi . back ( ) ] ) Qi . pop_back ( ) ; Qi . push_back ( i ) ; } for ( ; i < n ; ++ i ) { cout << arr [ Qi . front ( ) ] << " ▁ " ; while ( ( ! Qi . empty ( ) ) && Qi . front ( ) <= i - k ) Qi . pop_front ( ) ; while ( ( ! Qi . empty ( ) ) && arr [ i ] >= arr [ Qi . back ( ) ] ) Qi . pop_back ( ) ; Qi . push_back ( i ) ; } cout << arr [ Qi . front ( ) ] ; } int main ( ) { int arr [ ] = { 12 , 1 , 78 , 90 , 57 , 89 , 56 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 3 ; printKMax ( arr , n , k ) ; return 0 ; }

Index/key variables: i
Accumulator variables: stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int SumOfKsubArray ( int arr [ ] , int n , int k ) { int sum = 0 ; deque < int > S ( k ) , G ( k ) ; int i = 0 ; for ( i = 0 ; i < k ; i ++ ) { while ( ( ! S . empty ( ) ) && arr [ S . back ( ) ] >= arr [ i ] ) S . pop_back ( ) ; while ( ( ! G . empty ( ) ) && arr [ G . back ( ) ] <= arr [ i ] ) G . pop_back ( ) ; G . push_back ( i ) ; S . push_back ( i ) ; } for ( ; i < n ; i ++ ) { sum += arr [ S . front ( ) ] + arr [ G . front ( ) ] ; while ( ! S . empty ( ) && S . front ( ) <= i - k ) S . pop_front ( ) ; while ( ! G . empty ( ) && G . front ( ) <= i - k ) G . pop_front ( ) ; while ( ( ! S . empty ( ) ) && arr [ S . back ( ) ] >= arr [ i ] ) S . pop_back ( ) ; while ( ( ! G . empty ( ) ) && arr [ G . back ( ) ] <= arr [ i ] ) G . pop_back ( ) ; G . push_back ( i ) ; S . push_back ( i ) ; } sum += arr [ S . front ( ) ] + arr [ G . front ( ) ] ; return sum ; } int main ( ) { int arr [ ] = { 2 , 5 , -1 , 7 , -3 , -1 , -2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 3 ; cout << SumOfKsubArray ( arr , n , k ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; struct Node * newNode ( int x ) { struct Node * temp = new Node ; temp -> data = x ; temp -> left = temp -> right = NULL ; return temp ; } ; int count ( Node * root ) { if ( root == NULL ) return 0 ; return count ( root -> left ) + count ( root -> right ) + 1 ; } int checkRec ( Node * root , int n , bool & res ) { if ( root == NULL ) return 0 ; int c = checkRec ( root -> left , n , res ) + 1 + checkRec ( root -> right , n , res ) ; if ( c == n - c ) res = true ; return c ; } bool check ( Node * root ) { int n = count ( root ) ; bool res = false ; checkRec ( root , n , res ) ; return res ; } int main ( ) { struct Node * root = newNode ( 5 ) ; root -> left = newNode ( 1 ) ; root -> right = newNode ( 6 ) ; root -> left -> left = newNode ( 3 ) ; root -> right -> left = newNode ( 7 ) ; root -> right -> right = newNode ( 4 ) ; check ( root ) ? printf ( " YES " ) : printf ( " NO " ) ; return 0 ; }

Accumulator variables: stdc
Boolean variables: res
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
#define N  3
#define M  4
using namespace std ; void printDistance ( int mat [ N ] [ M ] ) { int ans [ N ] [ M ] ; for ( int i = 0 ; i < N ; i ++ ) for ( int j = 0 ; j < M ; j ++ ) ans [ i ] [ j ] = INT_MAX ; for ( int i = 0 ; i < N ; i ++ ) for ( int j = 0 ; j < M ; j ++ ) { for ( int k = 0 ; k < N ; k ++ ) for ( int l = 0 ; l < M ; l ++ ) { if ( mat [ k ] [ l ] == 1 ) ans [ i ] [ j ] = min ( ans [ i ] [ j ] , abs ( i - k ) + abs ( j - l ) ) ; } } for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) cout << ans [ i ] [ j ] << " ▁ " ; cout << endl ; } } int main ( ) { int mat [ N ] [ M ] = { 0 , 0 , 0 , 1 , 0 , 0 , 1 , 1 , 0 , 1 , 1 , 0 } ; printDistance ( mat ) ; return 0 ; }

Index/key variables: M, N, i, j, k, l
Accumulator variables: i, j, k, l, stdc
Iterator variables: i, j, k, l
C++ program:
#include <bits/stdc++.h>
#define MAX  500
#define N  3
#define M  4
using namespace std ; class graph { private : vector < int > g [ MAX ] ; int n , m ; public : graph ( int a , int b ) { n = a ; m = b ; } void createGraph ( ) { int k = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= m ; j ++ ) { if ( i == n ) { if ( j != m ) { g [ k ] . push_back ( k + 1 ) ; g [ k + 1 ] . push_back ( k ) ; } } else if ( j == m ) { g [ k ] . push_back ( k + m ) ; g [ k + m ] . push_back ( k ) ; } else { g [ k ] . push_back ( k + 1 ) ; g [ k + 1 ] . push_back ( k ) ; g [ k ] . push_back ( k + m ) ; g [ k + m ] . push_back ( k ) ; } k ++ ; } } } void bfs ( bool visit [ ] , int dist [ ] , queue < int > q ) { while ( ! q . empty ( ) ) { int temp = q . front ( ) ; q . pop ( ) ; for ( int i = 0 ; i < g [ temp ] . size ( ) ; i ++ ) { if ( visit [ g [ temp ] [ i ] ] != 1 ) { dist [ g [ temp ] [ i ] ] = min ( dist [ g [ temp ] [ i ] ] , dist [ temp ] + 1 ) ; q . push ( g [ temp ] [ i ] ) ; visit [ g [ temp ] [ i ] ] = 1 ; } } } } void print ( int dist [ ] ) { for ( int i = 1 , c = 1 ; i <= n * m ; i ++ , c ++ ) { cout << dist [ i ] << " ▁ " ; if ( c % m == 0 ) cout << endl ; } } } ; void findMinDistance ( bool mat [ N ] [ M ] ) { graph g1 ( N , M ) ; g1 . createGraph ( ) ; int dist [ MAX ] ; bool visit [ MAX ] = { 0 } ; for ( int i = 1 ; i <= M * N ; i ++ ) { dist [ i ] = INT_MAX ; visit [ i ] = 0 ; } int k = 1 ; queue < int > q ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( mat [ i ] [ j ] == 1 ) { dist [ k ] = 0 ; visit [ k ] = 1 ; q . push ( k ) ; } k ++ ; } } g1 . bfs ( visit , dist , q ) ; g1 . print ( dist ) ; } int main ( ) { bool mat [ N ] [ M ] = { 0 , 0 , 0 , 1 , 0 , 0 , 1 , 1 , 0 , 1 , 1 , 0 } ; findMinDistance ( mat ) ; return 0 ; }

Index/key variables: M, MAX, N, i, j, k, temp
Accumulator variables: c, i, j, k, stdc
Iterator variables: i, j
Class/struct names: graph
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printFirstNegativeInteger ( int arr [ ] , int n , int k ) { bool flag ; for ( int i = 0 ; i < ( n - k + 1 ) ; i ++ ) { flag = false ; for ( int j = 0 ; j < k ; j ++ ) { if ( arr [ i + j ] < 0 ) { cout << arr [ i + j ] << " ▁ " ; flag = true ; break ; } } if ( ! flag ) cout << "0" << " ▁ " ; } } int main ( ) { int arr [ ] = { 12 , -1 , -7 , 8 , -15 , 30 , 16 , 28 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 3 ; printFirstNegativeInteger ( arr , n , k ) ; return 0 ; }

Accumulator variables: i, j, stdc
Iterator variables: i, j
Boolean variables: flag
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printFirstNegativeInteger ( int arr [ ] , int n , int k ) { deque < int > Di ; int i ; for ( i = 0 ; i < k ; i ++ ) if ( arr [ i ] < 0 ) Di . push_back ( i ) ; for ( ; i < n ; i ++ ) { if ( ! Di . empty ( ) ) cout << arr [ Di . front ( ) ] << " ▁ " ; else cout << "0" << " ▁ " ; while ( ( ! Di . empty ( ) ) && Di . front ( ) < ( i - k + 1 ) ) Di . pop_front ( ) ; if ( arr [ i ] < 0 ) Di . push_back ( i ) ; } if ( ! Di . empty ( ) ) cout << arr [ Di . front ( ) ] << " ▁ " ; else cout << "0" << " ▁ " ; } int main ( ) { int arr [ ] = { 12 , -1 , -7 , 8 , -15 , 30 , 16 , 28 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 3 ; printFirstNegativeInteger ( arr , n , k ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; void printFirstNegativeInteger ( int arr [ ] , int k , int n ) { int firstNegativeIndex = 0 ; int firstNegativeElement ; for ( int i = k - 1 ; i < n ; i ++ ) { while ( ( firstNegativeIndex < i ) && ( firstNegativeIndex <= i - k arr [ firstNegativeIndex ] > 0 ) ) { firstNegativeIndex ++ ; } if ( arr [ firstNegativeIndex ] < 0 ) { firstNegativeElement = arr [ firstNegativeIndex ] ; } else { firstNegativeElement = 0 ; } cout << firstNegativeElement << " ▁ " ; } } int main ( ) { int arr [ ] = { 12 , -1 , -7 , 8 , -15 , 30 , 16 , 28 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 3 ; printFirstNegativeInteger ( arr , k , n ) ; }

Index/key variables: firstNegativeIndex
Accumulator variables: firstNegativeIndex, i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { struct Node * left , * right ; int data ; } ; bool areAnagrams ( Node * root1 , Node * root2 ) { if ( root1 == NULL && root2 == NULL ) return true ; if ( root1 == NULL root2 == NULL ) return false ; queue < Node * > q1 , q2 ; q1 . push ( root1 ) ; q2 . push ( root2 ) ; while ( 1 ) { int n1 = q1 . size ( ) , n2 = q2 . size ( ) ; if ( n1 != n2 ) return false ; if ( n1 == 0 ) break ; vector < int > curr_level1 , curr_level2 ; while ( n1 > 0 ) { Node * node1 = q1 . front ( ) ; q1 . pop ( ) ; if ( node1 -> left != NULL ) q1 . push ( node1 -> left ) ; if ( node1 -> right != NULL ) q1 . push ( node1 -> right ) ; n1 -- ; Node * node2 = q2 . front ( ) ; q2 . pop ( ) ; if ( node2 -> left != NULL ) q2 . push ( node2 -> left ) ; if ( node2 -> right != NULL ) q2 . push ( node2 -> right ) ; curr_level1 . push_back ( node1 -> data ) ; curr_level2 . push_back ( node2 -> data ) ; } sort ( curr_level1 . begin ( ) , curr_level1 . end ( ) ) ; sort ( curr_level2 . begin ( ) , curr_level2 . end ( ) ) ; if ( curr_level1 != curr_level2 ) return false ; } return true ; } Node * newNode ( int data ) { Node * temp = new Node ; temp -> data = data ; temp -> left = temp -> right = NULL ; return temp ; } int main ( ) { struct Node * root1 = newNode ( 1 ) ; root1 -> left = newNode ( 3 ) ; root1 -> right = newNode ( 2 ) ; root1 -> right -> left = newNode ( 5 ) ; root1 -> right -> right = newNode ( 4 ) ; struct Node * root2 = newNode ( 1 ) ; root2 -> left = newNode ( 2 ) ; root2 -> right = newNode ( 3 ) ; root2 -> left -> left = newNode ( 4 ) ; root2 -> left -> right = newNode ( 5 ) ; areAnagrams ( root1 , root2 ) ? cout << " Yes " : cout << " No " ; return 0 ; }

Accumulator variables: n1, stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; Node * newNode ( int data ) { Node * temp = new Node ; temp -> data = data ; temp -> left = temp -> right = NULL ; return temp ; } int search ( int arr [ ] , int strt , int end , int value ) { for ( int i = strt ; i <= end ; i ++ ) { if ( arr [ i ] == value ) return i ; } } Node * buildTree ( int in [ ] , int pre [ ] , int inStrt , int inEnd ) { static int preIndex = 0 ; if ( inStrt > inEnd ) return NULL ; Node * tNode = newNode ( pre [ preIndex ++ ] ) ; if ( inStrt == inEnd ) return tNode ; int inIndex = search ( in , inStrt , inEnd , tNode -> data ) ; tNode -> left = buildTree ( in , pre , inStrt , inIndex - 1 ) ; tNode -> right = buildTree ( in , pre , inIndex + 1 , inEnd ) ; return tNode ; } int checkPostorder ( Node * node , int postOrder [ ] , int index ) { if ( node == NULL ) return index ; index = checkPostorder ( node -> left , postOrder , index ) ; index = checkPostorder ( node -> right , postOrder , index ) ; if ( node -> data == postOrder [ index ] ) index ++ ; else return -1 ; return index ; } int main ( ) { int inOrder [ ] = { 4 , 2 , 5 , 1 , 3 } ; int preOrder [ ] = { 1 , 2 , 4 , 5 , 3 } ; int postOrder [ ] = { 4 , 5 , 2 , 3 , 1 } ; int len = sizeof ( inOrder ) / sizeof ( inOrder [ 0 ] ) ; Node * root = buildTree ( inOrder , preOrder , 0 , len - 1 ) ; int index = checkPostorder ( root , postOrder , 0 ) ; if ( index == len ) cout << " Yes " ; else cout << " No " ; return 0 ; }

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