dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; class node { public : int data ; node * left ; node * right ; } ; node * newNode ( int data ) { node * temp = new node ( ) ; temp -> data = data ; temp -> left = temp -> right = NULL ; return temp ; } node * constructTreeUtil ( int pre [ ] , int post [ ] , int * preIndex , int l , int h , int size ) { if ( * preIndex >= size l > h ) return NULL ; node * root = newNode ( pre [ * preIndex ] ) ; ++ * preIndex ; if ( l == h ) return root ; int i ; for ( i = l ; i <= h ; ++ i ) if ( pre [ * preIndex ] == post [ i ] ) break ; if ( i <= h ) { root -> left = constructTreeUtil ( pre , post , preIndex , l , i , size ) ; root -> right = constructTreeUtil ( pre , post , preIndex , i + 1 , h , size ) ; } return root ; } node * constructTree ( int pre [ ] , int post [ ] , int size ) { int preIndex = 0 ; return constructTreeUtil ( pre , post , & preIndex , 0 , size - 1 , size ) ; } void printInorder ( node * node ) { if ( node == NULL ) return ; printInorder ( node -> left ) ; cout << node -> data << " ▁ " ; printInorder ( node -> right ) ; } int main ( ) { int pre [ ] = { 1 , 2 , 4 , 8 , 9 , 5 , 3 , 6 , 7 } ; int post [ ] = { 8 , 9 , 4 , 5 , 2 , 6 , 7 , 3 , 1 } ; int size = sizeof ( pre ) / sizeof ( pre [ 0 ] ) ; node * root = constructTree ( pre , post , size ) ; cout << " Inorder ▁ traversal ▁ of ▁ the ▁ constructed ▁ tree : ▁ STRNEWLINE " ; printInorder ( root ) ; return 0 ; }

Index/key variables: i
Accumulator variables: stdc
Iterator variables: i
Class/struct names: node
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int key ; Node * left , * right ; bool isThreaded ; } ; Node * createThreaded ( Node * root ) { if ( root == NULL ) return NULL ; if ( root -> left == NULL && root -> right == NULL ) return root ; if ( root -> left != NULL ) { Node * l = createThreaded ( root -> left ) ; l -> right = root ; l -> isThreaded = true ; } if ( root -> right == NULL ) return root ; return createThreaded ( root -> right ) ; } Node * leftMost ( Node * root ) { while ( root != NULL && root -> left != NULL ) root = root -> left ; return root ; } void inOrder ( Node * root ) { if ( root == NULL ) return ; Node * cur = leftMost ( root ) ; while ( cur != NULL ) { cout << cur -> key << " ▁ " ; if ( cur -> isThreaded ) cur = cur -> right ; else cur = leftMost ( cur -> right ) ; } } Node * newNode ( int key ) { Node * temp = new Node ; temp -> left = temp -> right = NULL ; temp -> key = key ; return temp ; } int main ( ) { Node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 5 ) ; root -> right -> left = newNode ( 6 ) ; root -> right -> right = newNode ( 7 ) ; createThreaded ( root ) ; cout << " Inorder ▁ traversal ▁ of ▁ created ▁ " " threaded ▁ tree ▁ is STRNEWLINE " ; inOrder ( root ) ; return 0 ; }

Accumulator variables: stdc
Boolean variables: isThreaded
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { Node * left , * right , * parent ; int key ; } ; Node * newNode ( int item ) { Node * temp = new Node ; temp -> key = item ; temp -> parent = 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 ) ; node -> left -> parent = node ; } else if ( key > node -> key ) { node -> right = insert ( node -> right , key ) ; node -> right -> parent = node ; } return node ; } void inorder ( Node * root ) { bool leftdone = false ; while ( root ) { if ( ! leftdone ) { while ( root -> left ) root = root -> left ; } printf ( " % d ▁ " , root -> key ) ; leftdone = true ; if ( root -> right ) { leftdone = false ; root = root -> right ; } else if ( root -> parent ) { while ( root -> parent && root == root -> parent -> right ) root = root -> parent ; if ( ! root -> parent ) break ; root = root -> parent ; } else break ; } } int main ( void ) { Node * root = NULL ; root = insert ( root , 24 ) ; root = insert ( root , 27 ) ; root = insert ( root , 29 ) ; root = insert ( root , 34 ) ; root = insert ( root , 14 ) ; root = insert ( root , 4 ) ; root = insert ( root , 10 ) ; root = insert ( root , 22 ) ; root = insert ( root , 13 ) ; root = insert ( root , 3 ) ; root = insert ( root , 2 ) ; root = insert ( root , 6 ) ; printf ( " Inorder ▁ traversal ▁ is ▁ STRNEWLINE " ) ; inorder ( root ) ; return 0 ; }

Accumulator variables: stdc
Boolean variables: leftdone
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printSorted ( int arr [ ] , int start , int end ) { if ( start > end ) return ; printSorted ( arr , start * 2 + 1 , end ) ; cout << arr [ start ] << " ▁ " ; printSorted ( arr , start * 2 + 2 , end ) ; } int main ( ) { int arr [ ] = { 4 , 2 , 5 , 1 , 3 } ; int arr_size = sizeof ( arr ) / sizeof ( int ) ; printSorted ( arr , 0 , arr_size - 1 ) ; getchar ( ) ; return 0 ; }

Index/key variables: start
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; class node { public : int key ; node * left ; node * right ; } ; node * newNode ( int key ) { node * Node = new node ( ) ; Node -> key = key ; Node -> left = NULL ; Node -> right = NULL ; return ( Node ) ; } int Ceil ( node * root , int input ) { if ( root == NULL ) return -1 ; if ( root -> key == input ) return root -> key ; if ( root -> key < input ) return Ceil ( root -> right , input ) ; int ceil = Ceil ( root -> left , input ) ; return ( ceil >= input ) ? ceil : root -> key ; } int main ( ) { node * root = newNode ( 8 ) ; root -> left = newNode ( 4 ) ; root -> right = newNode ( 12 ) ; root -> left -> left = newNode ( 2 ) ; root -> left -> right = newNode ( 6 ) ; root -> right -> left = newNode ( 10 ) ; root -> right -> right = newNode ( 14 ) ; for ( int i = 0 ; i < 16 ; i ++ ) cout << i << " ▁ " << Ceil ( root , i ) << endl ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
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 ; } void printInorder ( Node * node ) { if ( node == NULL ) return ; printInorder ( node -> left ) ; printf ( " % d ▁ " , node -> data ) ; printInorder ( node -> right ) ; } Node * constructBinaryTreeUtil ( int pre [ ] , int preM [ ] , int & preIndex , int l , int h , int size ) { if ( preIndex >= size l > h ) return NULL ; Node * root = newNode ( pre [ preIndex ] ) ; ++ ( preIndex ) ; if ( l == h ) return root ; int i ; for ( i = l ; i <= h ; ++ i ) if ( pre [ preIndex ] == preM [ i ] ) break ; if ( i <= h ) { root -> left = constructBinaryTreeUtil ( pre , preM , preIndex , i , h , size ) ; root -> right = constructBinaryTreeUtil ( pre , preM , preIndex , l + 1 , i - 1 , size ) ; } return root ; } void constructBinaryTree ( Node * root , int pre [ ] , int preMirror [ ] , int size ) { int preIndex = 0 ; int preMIndex = 0 ; root = constructBinaryTreeUtil ( pre , preMirror , preIndex , 0 , size - 1 , size ) ; printInorder ( root ) ; } int main ( ) { int preOrder [ ] = { 1 , 2 , 4 , 5 , 3 , 6 , 7 } ; int preOrderMirror [ ] = { 1 , 3 , 7 , 6 , 2 , 5 , 4 } ; int size = sizeof ( preOrder ) / sizeof ( preOrder [ 0 ] ) ; Node * root = new Node ; constructBinaryTree ( root , preOrder , preOrderMirror , size ) ; return 0 ; }

Index/key variables: i, preIndex
Accumulator variables: 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 ( int value ) { data = value ; left = right = NULL ; } } ; void floorCeilBSTHelper ( Node * root , int key , int & floor , int & ceil ) { while ( root ) { if ( root -> data == key ) { ceil = root -> data ; floor = root -> data ; return ; } if ( key > root -> data ) { floor = root -> data ; root = root -> right ; } else { ceil = root -> data ; root = root -> left ; } } return ; } void floorCeilBST ( Node * root , int key ) { int floor = -1 , ceil = -1 ; floorCeilBSTHelper ( root , key , floor , ceil ) ; cout << key << ' ▁ ' << floor << ' ▁ ' << ceil << ' ' ; } int main ( ) { Node * root = new Node ( 8 ) ; root -> left = new Node ( 4 ) ; root -> right = new Node ( 12 ) ; root -> left -> left = new Node ( 2 ) ; root -> left -> right = new Node ( 6 ) ; root -> right -> left = new Node ( 10 ) ; root -> right -> right = new Node ( 14 ) ; for ( int i = 0 ; i < 16 ; i ++ ) floorCeilBST ( root , i ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct node { int key ; int count ; struct node * left , * right ; } ; struct node * newNode ( int item ) { struct node * temp = ( struct node * ) malloc ( sizeof ( struct node ) ) ; temp -> key = item ; temp -> left = temp -> right = NULL ; temp -> count = 1 ; return temp ; } void inorder ( struct node * root ) { if ( root != NULL ) { inorder ( root -> left ) ; cout << root -> key << " ( " << root -> count << " ) ▁ " ; inorder ( root -> right ) ; } } struct node * insert ( struct node * node , int key ) { if ( node == NULL ) return newNode ( key ) ; if ( key == node -> key ) { ( node -> count ) ++ ; return node ; } if ( key < node -> key ) node -> left = insert ( node -> left , key ) ; else node -> right = insert ( node -> right , key ) ; return node ; } struct node * minValueNode ( struct node * node ) { struct node * current = node ; while ( current -> left != NULL ) current = current -> left ; return current ; } struct node * deleteNode ( struct node * root , int key ) { if ( root == NULL ) return root ; if ( key < root -> key ) root -> left = deleteNode ( root -> left , key ) ; else if ( key > root -> key ) root -> right = deleteNode ( root -> right , key ) ; else { if ( root -> count > 1 ) { ( root -> count ) -- ; return root ; } if ( root -> left == NULL ) { struct node * temp = root -> right ; free ( root ) ; return temp ; } else if ( root -> right == NULL ) { struct node * temp = root -> left ; free ( root ) ; return temp ; } struct node * temp = minValueNode ( root -> right ) ; root -> key = temp -> key ; root -> right = deleteNode ( root -> right , temp -> key ) ; } return root ; } int main ( ) { struct node * root = NULL ; root = insert ( root , 12 ) ; root = insert ( root , 10 ) ; root = insert ( root , 20 ) ; root = insert ( root , 9 ) ; root = insert ( root , 11 ) ; root = insert ( root , 10 ) ; root = insert ( root , 12 ) ; root = insert ( root , 12 ) ; cout << " Inorder ▁ traversal ▁ of ▁ the ▁ given ▁ tree ▁ " << endl ; inorder ( root ) ; cout << " Delete 20 " root = deleteNode ( root , 20 ) ; cout << " Inorder ▁ traversal ▁ of ▁ the ▁ modified ▁ tree ▁ STRNEWLINE " ; inorder ( root ) ; cout << " Delete 12 " root = deleteNode ( root , 12 ) ; cout << " Inorder ▁ traversal ▁ of ▁ the ▁ modified ▁ tree ▁ STRNEWLINE " ; inorder ( root ) ; cout << " Delete 9 " root = deleteNode ( root , 9 ) ; cout << " Inorder ▁ traversal ▁ of ▁ the ▁ modified ▁ tree ▁ STRNEWLINE " ; inorder ( root ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: node
C++ program:
#include <bits/stdc++.h>
using namespace std ; class node { public : int key ; node * left , * right ; } ; node * newNode ( int item ) { node * temp = new node ; temp -> key = item ; temp -> left = temp -> right = NULL ; return temp ; } void inorder ( node * root ) { if ( root != NULL ) { inorder ( root -> left ) ; cout << root -> key << " ▁ " ; inorder ( root -> right ) ; } } node * insert ( node * node , int key ) { if ( node == NULL ) return newNode ( key ) ; if ( key < node -> key ) node -> left = insert ( node -> left , key ) ; else node -> right = insert ( node -> right , key ) ; return node ; } node * minValueNode ( node * Node ) { node * current = Node ; while ( current -> left != NULL ) current = current -> left ; return current ; } node * deleteNode ( node * root , int key ) { if ( root == NULL ) return root ; if ( key < root -> key ) root -> left = deleteNode ( root -> left , key ) ; else if ( key > root -> key ) root -> right = deleteNode ( root -> right , key ) ; else { if ( root -> left == NULL ) { node * temp = root -> right ; free ( root ) ; return temp ; } else if ( root -> right == NULL ) { node * temp = root -> left ; free ( root ) ; return temp ; } node * temp = minValueNode ( root -> right ) ; root -> key = temp -> key ; root -> right = deleteNode ( root -> right , temp -> key ) ; } return root ; } node * changeKey ( node * root , int oldVal , int newVal ) { root = deleteNode ( root , oldVal ) ; root = insert ( root , newVal ) ; return root ; } int main ( ) { node * root = NULL ; root = insert ( root , 50 ) ; root = insert ( root , 30 ) ; root = insert ( root , 20 ) ; root = insert ( root , 40 ) ; root = insert ( root , 70 ) ; root = insert ( root , 60 ) ; root = insert ( root , 80 ) ; cout << " Inorder ▁ traversal ▁ of ▁ the ▁ given ▁ tree ▁ STRNEWLINE " ; inorder ( root ) ; root = changeKey ( root , 40 , 10 ) ; cout << " Inorder traversal of the modified tree " ; inorder ( root ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: node
C++ program:
#include <iostream>
#include <stack>
using namespace std ; struct Node { int key ; struct Node * left , * right ; } ; Node * newNode ( int ele ) { Node * temp = new Node ; temp -> key = ele ; temp -> left = temp -> right = NULL ; return temp ; } void printCommon ( Node * root1 , Node * root2 ) { stack < Node * > stack1 , s1 , s2 ; while ( 1 ) { if ( root1 ) { s1 . push ( root1 ) ; root1 = root1 -> left ; } else if ( root2 ) { s2 . push ( root2 ) ; root2 = root2 -> left ; } else if ( ! s1 . empty ( ) && ! s2 . empty ( ) ) { root1 = s1 . top ( ) ; root2 = s2 . top ( ) ; if ( root1 -> key == root2 -> key ) { cout << root1 -> key << " ▁ " ; s1 . pop ( ) ; s2 . pop ( ) ; root1 = root1 -> right ; root2 = root2 -> right ; } else if ( root1 -> key < root2 -> key ) { s1 . pop ( ) ; root1 = root1 -> right ; root2 = NULL ; } else if ( root1 -> key > root2 -> key ) { s2 . pop ( ) ; root2 = root2 -> right ; root1 = NULL ; } } else break ; } } void inorder ( struct Node * root ) { if ( root ) { inorder ( root -> left ) ; cout << root -> key << " ▁ " ; inorder ( root -> right ) ; } } struct Node * insert ( struct 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 main ( ) { Node * root1 = NULL ; root1 = insert ( root1 , 5 ) ; root1 = insert ( root1 , 1 ) ; root1 = insert ( root1 , 10 ) ; root1 = insert ( root1 , 0 ) ; root1 = insert ( root1 , 4 ) ; root1 = insert ( root1 , 7 ) ; root1 = insert ( root1 , 9 ) ; Node * root2 = NULL ; root2 = insert ( root2 , 10 ) ; root2 = insert ( root2 , 7 ) ; root2 = insert ( root2 , 20 ) ; root2 = insert ( root2 , 4 ) ; root2 = insert ( root2 , 9 ) ; cout << " Tree ▁ 1 ▁ : ▁ " ; inorder ( root1 ) ; cout << endl ; cout << " Tree ▁ 2 ▁ : ▁ " ; inorder ( root2 ) ; cout << " Common Nodes : " printCommon ( root1 , root2 ) ; return 0 ; }

Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int binarySearch ( int inorder [ ] , int l , int r , int d ) { int mid = ( l + r ) >> 1 ; if ( inorder [ mid ] == d ) return mid ; else if ( inorder [ mid ] > d ) return binarySearch ( inorder , l , mid - 1 , d ) ; else return binarySearch ( inorder , mid + 1 , r , d ) ; } int ind = 0 ; void leafNodesRec ( int preorder [ ] , int inorder [ ] , int l , int r , int * ind , int n ) { if ( l == r ) { printf ( " % d ▁ " , inorder [ l ] ) ; * ind = * ind + 1 ; return ; } if ( l < 0 l > r r >= n ) return ; int loc = binarySearch ( inorder , l , r , preorder [ * ind ] ) ; * ind = * ind + 1 ; leafNodesRec ( preorder , inorder , l , loc - 1 , ind , n ) ; leafNodesRec ( preorder , inorder , loc + 1 , r , ind , n ) ; } void leafNodes ( int preorder [ ] , int n ) { int inorder [ n ] ; for ( int i = 0 ; i < n ; i ++ ) inorder [ i ] = preorder [ i ] ; sort ( inorder , inorder + n ) ; leafNodesRec ( preorder , inorder , 0 , n - 1 , & ind , n ) ; } int main ( ) { int preorder [ ] = { 890 , 325 , 290 , 530 , 965 } ; int n = sizeof ( preorder ) / sizeof ( preorder [ 0 ] ) ; leafNodes ( preorder , n ) ; return 0 ; }

Index/key variables: i, l, mid, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void leafNode ( int preorder [ ] , int n ) { stack < int > s ; for ( int i = 0 , j = 1 ; j < n ; i ++ , j ++ ) { bool found = false ; if ( preorder [ i ] > preorder [ j ] ) s . push ( preorder [ i ] ) ; else { while ( ! s . empty ( ) ) { if ( preorder [ j ] > s . top ( ) ) { s . pop ( ) ; found = true ; } else break ; } } if ( found ) cout << preorder [ i ] << " ▁ " ; } cout << preorder [ n - 1 ] ; } int main ( ) { int preorder [ ] = { 890 , 325 , 290 , 530 , 965 } ; int n = sizeof ( preorder ) / sizeof ( preorder [ 0 ] ) ; leafNode ( preorder , n ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i
Boolean variables: found
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isLeaf ( int pre [ ] , int & i , int n , int min , int max ) { if ( i >= n ) return false ; if ( pre [ i ] > min && pre [ i ] < max ) { i ++ ; bool left = isLeaf ( pre , i , n , min , pre [ i - 1 ] ) ; bool right = isLeaf ( pre , i , n , pre [ i - 1 ] , max ) ; if ( ! left && ! right ) cout << pre [ i - 1 ] << " ▁ " ; return true ; } return false ; } void printLeaves ( int preorder [ ] , int n ) { int i = 0 ; isLeaf ( preorder , i , n , INT_MIN , INT_MAX ) ; } int main ( ) { int preorder [ ] = { 890 , 325 , 290 , 530 , 965 } ; int n = sizeof ( preorder ) / sizeof ( preorder [ 0 ] ) ; printLeaves ( preorder , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
C++ program:
#include <bits/stdc++.h>
struct Node { int key ; struct Node * left , * right , * parent ; } ; struct Node * newNode ( int item ) { struct Node * temp = new Node ; temp -> key = item ; temp -> left = temp -> right = NULL ; temp -> parent = NULL ; return temp ; } void inorder ( struct Node * root ) { if ( root != NULL ) { inorder ( root -> left ) ; printf ( " Node ▁ : ▁ % d , ▁ " , root -> key ) ; if ( root -> parent == NULL ) printf ( " Parent ▁ : ▁ NULL ▁ STRNEWLINE " ) ; else printf ( " Parent ▁ : ▁ % d ▁ STRNEWLINE " , root -> parent -> key ) ; inorder ( root -> right ) ; } } struct Node * insert ( struct Node * node , int key ) { if ( node == NULL ) return newNode ( key ) ; if ( key < node -> key ) { Node * lchild = insert ( node -> left , key ) ; node -> left = lchild ; lchild -> parent = node ; } else if ( key > node -> key ) { Node * rchild = insert ( node -> right , key ) ; node -> right = rchild ; rchild -> parent = node ; } return node ; } int main ( ) { struct Node * root = NULL ; root = insert ( root , 50 ) ; insert ( root , 30 ) ; insert ( root , 20 ) ; insert ( root , 40 ) ; insert ( root , 70 ) ; insert ( root , 60 ) ; insert ( root , 80 ) ; inorder ( root ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
struct node { int data ; struct node * left ; struct node * right ; } ; struct node * newNode ( int data ) { struct node * temp = new struct node ; temp -> data = data ; temp -> left = NULL ; temp -> right = NULL ; return temp ; } struct node * constructTreeUtil ( int pre [ ] , char preLN [ ] , int * index_ptr , int n ) { int index = * index_ptr ; if ( index == n ) return NULL ; struct node * temp = newNode ( pre [ index ] ) ; ( * index_ptr ) ++ ; if ( preLN [ index ] == ' N ' ) { temp -> left = constructTreeUtil ( pre , preLN , index_ptr , n ) ; temp -> right = constructTreeUtil ( pre , preLN , index_ptr , n ) ; } return temp ; } struct node * constructTree ( int pre [ ] , char preLN [ ] , int n ) { int index = 0 ; return constructTreeUtil ( pre , preLN , & index , n ) ; } void printInorder ( struct node * node ) { if ( node == NULL ) return ; printInorder ( node -> left ) ; printf ( " % d ▁ " , node -> data ) ; printInorder ( node -> right ) ; } int main ( ) { struct node * root = NULL ; int pre [ ] = { 10 , 30 , 20 , 5 , 15 } ; char preLN [ ] = { ' N ' , ' N ' , ' L ' , ' L ' , ' L ' } ; int n = sizeof ( pre ) / sizeof ( pre [ 0 ] ) ; root = constructTree ( pre , preLN , n ) ; printf ( " Following ▁ is ▁ Inorder ▁ Traversal ▁ of ▁ the ▁ Constructed ▁ Binary ▁ Tree : ▁ STRNEWLINE " ) ; printInorder ( root ) ; return 0 ; }

Index/key variables: index
Accumulator variables: stdc
Class/struct names: node
C++ program:
#include <bits/stdc++.h>
using namespace std ; void pairs ( int arr [ ] , int n , int k ) { int smallest = INT_MAX ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) { if ( abs ( arr [ i ] + arr [ j ] - k ) < smallest ) { smallest = abs ( arr [ i ] + arr [ j ] - k ) ; count = 1 ; } else if ( abs ( arr [ i ] + arr [ j ] - k ) == smallest ) count ++ ; } cout << " Minimal ▁ Value ▁ = ▁ " << smallest << " STRNEWLINE " ; cout << " Total ▁ Pairs ▁ = ▁ " << count << " STRNEWLINE " ; } int main ( ) { int arr [ ] = { 3 , 5 , 7 , 5 , 1 , 9 , 9 } ; int k = 12 ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; pairs ( arr , n , k ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: count, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; Node * left , * right ; int leftSize ; } ; Node * newNode ( int data ) { Node * temp = new Node ; temp -> data = data ; temp -> left = temp -> right = NULL ; temp -> leftSize = 0 ; return temp ; } Node * insert ( Node * & root , int data ) { if ( ! root ) return newNode ( data ) ; if ( data <= root -> data ) { root -> left = insert ( root -> left , data ) ; root -> leftSize ++ ; } else root -> right = insert ( root -> right , data ) ; return root ; } int getRank ( Node * root , int x ) { if ( root -> data == x ) return root -> leftSize ; if ( x < root -> data ) { if ( ! root -> left ) return -1 ; else return getRank ( root -> left , x ) ; } else { if ( ! root -> right ) return -1 ; else { int rightSize = getRank ( root -> right , x ) ; if ( rightSize == -1 ) return -1 ; return root -> leftSize + 1 + rightSize ; } } } int main ( ) { int arr [ ] = { 5 , 1 , 4 , 4 , 5 , 9 , 7 , 13 , 3 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int x = 4 ; Node * root = NULL ; for ( int i = 0 ; i < n ; i ++ ) root = insert ( root , arr [ i ] ) ; cout << " Rank ▁ of ▁ " << x << " ▁ in ▁ stream ▁ is : ▁ " << getRank ( root , x ) << endl ; x = 13 ; cout << " Rank ▁ of ▁ " << x << " ▁ in ▁ stream ▁ is : ▁ " << getRank ( root , x ) << endl ; x = 8 ; cout << " Rank ▁ of ▁ " << x << " ▁ in ▁ stream ▁ is : ▁ " << getRank ( root , x ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, leftSize, stdc
Iterator variables: i
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int main ( ) { int a [ ] = { 5 , 1 , 14 , 4 , 15 , 9 , 7 , 20 , 11 } ; int key = 20 ; int arraySize = sizeof ( a ) / sizeof ( a [ 0 ] ) ; int count = 0 ; for ( int i = 0 ; i < arraySize ; i ++ ) { if ( a [ i ] <= key ) { count += 1 ; } } cout << " Rank ▁ of ▁ " << key << " ▁ in ▁ stream ▁ is : ▁ " << count - 1 << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i