dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
struct Node { int data ; Node * next ; } ; Node * newNode ( int data ) { Node * new_node = new Node ; new_node -> data = data ; new_node -> next = NULL ; return new_node ; } Node * fractionalNodes ( Node * head , int k ) { if ( k <= 0 head == NULL ) return NULL ; Node * fractionalNode = NULL ; int i = 0 ; for ( Node * temp = head ; temp != NULL ; temp = temp -> next ) { if ( i % k == 0 ) { if ( fractionalNode == NULL ) fractionalNode = head ; else fractionalNode = fractionalNode -> next ; } i ++ ; } return fractionalNode ; } void printList ( Node * node ) { while ( node != NULL ) { printf ( " % d ▁ " , node -> data ) ; node = node -> next ; } printf ( " STRNEWLINE " ) ; } int main ( void ) { Node * head = newNode ( 1 ) ; head -> next = newNode ( 2 ) ; head -> next -> next = newNode ( 3 ) ; head -> next -> next -> next = newNode ( 4 ) ; head -> next -> next -> next -> next = newNode ( 5 ) ; int k = 2 ; printf ( " List ▁ is ▁ " ) ; printList ( head ) ; Node * answer = fractionalNodes ( head , k ) ; printf ( " Fractional node is " printf ( " % d STRNEWLINE " , answer -> data ) ; return 0 ; }

Accumulator variables: i, stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
struct Node { int data ; Node * next ; } ; Node * newNode ( int data ) { Node * new_node = new Node ; new_node -> data = data ; new_node -> next = NULL ; return new_node ; } Node * modularNode ( Node * head , int k ) { if ( k <= 0 head == NULL ) return NULL ; int i = 1 ; Node * modularNode = NULL ; for ( Node * temp = head ; temp != NULL ; temp = temp -> next ) { if ( i % k == 0 ) modularNode = temp ; i ++ ; } return modularNode ; } int main ( void ) { Node * head = newNode ( 1 ) ; head -> next = newNode ( 2 ) ; head -> next -> next = newNode ( 3 ) ; head -> next -> next -> next = newNode ( 4 ) ; head -> next -> next -> next -> next = newNode ( 5 ) ; int k = 2 ; Node * answer = modularNode ( head , k ) ; printf ( " Modular node is " if ( answer != NULL ) printf ( " % d STRNEWLINE " , answer -> data ) ; else printf ( " null STRNEWLINE " ) ; return 0 ; }

Accumulator variables: i, stdc
Class/struct names: Node
C++ program:
struct node * search ( struct node * root , int key ) { if ( root == NULL root -> key == key ) return root ; if ( root -> key < key ) return search ( root -> right , key ) ; return search ( root -> left , key ) ; }

Class/struct names: node
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * left ; struct Node * right ; } ; struct Node * newNode ( int data ) { struct Node * node = new struct Node ; node -> data = data ; node -> left = NULL ; node -> right = NULL ; return ( node ) ; } struct Node * modifytree ( struct Node * root ) { struct Node * right = root -> right ; struct Node * rightMost = root ; if ( root -> left ) { rightMost = modifytree ( root -> left ) ; root -> right = root -> left ; root -> left = NULL ; } if ( ! right ) return rightMost ; rightMost -> right = right ; rightMost = modifytree ( right ) ; return rightMost ; } void printpre ( struct Node * root ) { while ( root != NULL ) { cout << root -> data << " ▁ " ; root = root -> right ; } } int main ( ) { struct Node * root = newNode ( 10 ) ; root -> left = newNode ( 8 ) ; root -> right = newNode ( 2 ) ; root -> left -> left = newNode ( 3 ) ; root -> left -> right = newNode ( 5 ) ; modifytree ( root ) ; printpre ( root ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; Node * left , * right ; } ; Node * getNode ( int data ) { Node * newNode = ( Node * ) malloc ( sizeof ( Node ) ) ; newNode -> data = data ; newNode -> left = newNode -> right = NULL ; return newNode ; } Node * LevelOrder ( Node * root , int data ) { if ( root == NULL ) { root = getNode ( data ) ; return root ; } if ( data <= root -> data ) root -> left = LevelOrder ( root -> left , data ) ; else root -> right = LevelOrder ( root -> right , data ) ; return root ; } Node * constructBst ( int arr [ ] , int n ) { if ( n == 0 ) return NULL ; Node * root = NULL ; for ( int i = 0 ; i < n ; i ++ ) root = LevelOrder ( root , arr [ i ] ) ; return root ; } void inorderTraversal ( Node * root ) { if ( ! root ) return ; inorderTraversal ( root -> left ) ; cout << root -> data << " ▁ " ; inorderTraversal ( root -> right ) ; } int main ( ) { int arr [ ] = { 7 , 4 , 12 , 3 , 6 , 8 , 1 , 5 , 10 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; Node * root = constructBst ( arr , n ) ; cout << " Inorder ▁ Traversal : ▁ " ; inorderTraversal ( root ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
Class/struct names: Node
C++ program:
#include <iostream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
using namespace std ; struct Node { int data ; struct Node * left ; struct Node * right ; } ; struct Node * newNode ( int data ) { struct Node * node = new struct Node ; node -> data = data ; node -> left = NULL ; node -> right = NULL ; return ( node ) ; } void modifytree ( struct Node * root ) { if ( root == NULL ) return ; stack < Node * > nodeStack ; nodeStack . push ( root ) ; struct Node * pre = NULL ; while ( nodeStack . empty ( ) == false ) { struct Node * node = nodeStack . top ( ) ; nodeStack . pop ( ) ; if ( node -> right ) nodeStack . push ( node -> right ) ; if ( node -> left ) nodeStack . push ( node -> left ) ; if ( pre != NULL ) { pre -> right = node ; } pre = node ; } } void printpre ( struct Node * root ) { while ( root != NULL ) { cout << root -> data << " ▁ " ; root = root -> right ; } } int main ( ) { struct Node * root = newNode ( 10 ) ; root -> left = newNode ( 8 ) ; root -> right = newNode ( 2 ) ; root -> left -> left = newNode ( 3 ) ; root -> left -> right = newNode ( 5 ) ; modifytree ( root ) ; printpre ( root ) ; return 0 ; }

Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int key ; struct Node * right , * left ; } ; Node * newNode ( int num ) { Node * temp = new Node ; temp -> key = num ; temp -> left = NULL ; temp -> right = NULL ; return temp ; } Node * createNLevelTree ( int arr [ ] , int n ) { Node * root = newNode ( arr [ 0 ] ) ; Node * temp = root ; for ( int i = 1 ; i < n ; i ++ ) { if ( temp -> key > arr [ i ] ) { temp -> left = newNode ( arr [ i ] ) ; temp = temp -> left ; } else { temp -> right = newNode ( arr [ i ] ) ; temp = temp -> right ; } } return root ; } bool isBST ( Node * root , int min , int max ) { if ( root == NULL ) return true ; if ( root -> key < min root -> key > max ) return false ; return ( isBST ( root -> left , min , ( root -> key ) - 1 ) && isBST ( root -> right , ( root -> key ) + 1 , max ) ) ; } bool canRepresentNLevelBST ( int arr [ ] , int n ) { Node * root = createNLevelTree ( arr , n ) ; return isBST ( root , INT_MIN , INT_MAX ) ; } int main ( ) { int arr [ ] = { 512 , 330 , 78 , 11 , 8 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; if ( canRepresentNLevelBST ( arr , n ) ) cout << " Yes " ; else cout << " No " ; 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 ; int main ( ) { int arr [ ] = { 5123 , 3300 , 783 , 1111 , 890 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int max = INT_MAX ; int min = INT_MIN ; bool flag = true ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] > arr [ i - 1 ] && arr [ i ] > min && arr [ i ] < max ) { min = arr [ i - 1 ] ; } else if ( arr [ i ] < arr [ i - 1 ] && arr [ i ] > min && arr [ i ] < max ) { max = arr [ i - 1 ] ; } else { flag = false ; break ; } } if ( flag ) { cout << " Yes " ; } else { cout << " No " ; } return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
Boolean variables: flag
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; Node * left , * right ; } ; void storeBSTNodes ( Node * root , vector < Node * > & nodes ) { if ( root == NULL ) return ; storeBSTNodes ( root -> left , nodes ) ; nodes . push_back ( root ) ; storeBSTNodes ( root -> right , nodes ) ; } Node * buildTreeUtil ( vector < Node * > & nodes , int start , int end ) { if ( start > end ) return NULL ; int mid = ( start + end ) / 2 ; Node * root = nodes [ mid ] ; root -> left = buildTreeUtil ( nodes , start , mid - 1 ) ; root -> right = buildTreeUtil ( nodes , mid + 1 , end ) ; return root ; } Node * buildTree ( Node * root ) { vector < Node * > nodes ; storeBSTNodes ( root , nodes ) ; int n = nodes . size ( ) ; return buildTreeUtil ( nodes , 0 , n - 1 ) ; } Node * newNode ( int data ) { Node * node = new Node ; node -> data = data ; node -> left = node -> right = NULL ; return ( node ) ; } void preOrder ( Node * node ) { if ( node == NULL ) return ; printf ( " % d ▁ " , node -> data ) ; preOrder ( node -> left ) ; preOrder ( node -> right ) ; } int main ( ) { Node * root = newNode ( 10 ) ; root -> left = newNode ( 8 ) ; root -> left -> left = newNode ( 7 ) ; root -> left -> left -> left = newNode ( 6 ) ; root -> left -> left -> left -> left = newNode ( 5 ) ; root = buildTree ( root ) ; printf ( " Preorder ▁ traversal ▁ of ▁ balanced ▁ " " BST ▁ is ▁ : ▁ STRNEWLINE " ) ; preOrder ( root ) ; return 0 ; }

Index/key variables: mid
Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct node { int data ; struct node * left ; struct node * right ; } ; struct node * newNode ( int data ) { struct node * node = ( struct node * ) malloc ( sizeof ( struct node ) ) ; node -> data = data ; node -> left = NULL ; node -> right = NULL ; return ( node ) ; } struct node * insert ( struct node * node , int data ) { if ( node == NULL ) return ( newNode ( data ) ) ; else { if ( data <= node -> data ) node -> left = insert ( node -> left , data ) ; else node -> right = insert ( node -> right , data ) ; return node ; } } int minValue ( struct node * node ) { struct node * current = node ; while ( current -> left != NULL ) { current = current -> left ; } return ( current -> data ) ; } int main ( ) { struct node * root = NULL ; root = insert ( root , 4 ) ; insert ( root , 2 ) ; insert ( root , 1 ) ; insert ( root , 3 ) ; insert ( root , 6 ) ; insert ( root , 5 ) ; cout << " Minimum value in BST is " getchar ( ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: node
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct NodeDetails { int data ; int min , max ; } ; bool levelOrderIsOfBST ( int arr [ ] , int n ) { if ( n == 0 ) return true ; queue < NodeDetails > q ; int i = 0 ; NodeDetails newNode ; newNode . data = arr [ i ++ ] ; newNode . min = INT_MIN ; newNode . max = INT_MAX ; q . push ( newNode ) ; while ( i != n && ! q . empty ( ) ) { NodeDetails temp = q . front ( ) ; q . pop ( ) ; if ( i < n && ( arr [ i ] < temp . data && arr [ i ] > temp . min ) ) { newNode . data = arr [ i ++ ] ; newNode . min = temp . min ; newNode . max = temp . data ; q . push ( newNode ) ; } if ( i < n && ( arr [ i ] > temp . data && arr [ i ] < temp . max ) ) { newNode . data = arr [ i ++ ] ; newNode . min = temp . data ; newNode . max = temp . max ; q . push ( newNode ) ; } } if ( i == n ) return true ; return false ; } int main ( ) { int arr [ ] = { 7 , 4 , 12 , 3 , 6 , 8 , 1 , 5 , 10 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; if ( levelOrderIsOfBST ( arr , n ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Class/struct names: NodeDetails
C++ program:
#include <bits/stdc++.h>
using namespace std ; class node { public : char data ; node * left ; node * right ; } ; int search ( char arr [ ] , int strt , int end , char value ) ; node * newNode ( char data ) ; node * buildTree ( char in [ ] , char 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 search ( char arr [ ] , int strt , int end , char value ) { int i ; for ( i = strt ; i <= end ; i ++ ) { if ( arr [ i ] == value ) return i ; } } node * newNode ( char data ) { node * Node = new node ( ) ; Node -> data = data ; Node -> left = NULL ; Node -> right = NULL ; return ( Node ) ; } void printInorder ( node * node ) { if ( node == NULL ) return ; printInorder ( node -> left ) ; cout << node -> data << " ▁ " ; printInorder ( node -> right ) ; } int main ( ) { char in [ ] = { ' D ' , ' B ' , ' E ' , ' A ' , ' F ' , ' C ' } ; char pre [ ] = { ' A ' , ' B ' , ' D ' , ' E ' , ' C ' , ' F ' } ; int len = sizeof ( in ) / sizeof ( in [ 0 ] ) ; node * root = buildTree ( in , pre , 0 , len - 1 ) ; cout << " Inorder ▁ traversal ▁ of ▁ the ▁ constructed ▁ tree ▁ is ▁ STRNEWLINE " ; printInorder ( root ) ; }

Index/key variables: i
Accumulator variables: i, preIndex, stdc
Iterator variables: i
Class/struct names: node
C++ program:
#include <bits/stdc++.h>
using namespace std ; class node { public : int data ; node * left , * right ; } ; struct node * lca ( struct node * root , int n1 , int n2 ) { while ( root != NULL ) { if ( root -> data > n1 && root -> data > n2 ) root = root -> left ; else if ( root -> data < n1 && root -> data < n2 ) root = root -> right ; else break ; } return root ; } node * newNode ( int data ) { node * Node = new node ( ) ; Node -> data = data ; Node -> left = Node -> right = NULL ; return ( Node ) ; } int main ( ) { node * root = newNode ( 20 ) ; root -> left = newNode ( 8 ) ; root -> right = newNode ( 22 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 12 ) ; root -> left -> right -> left = newNode ( 10 ) ; root -> left -> right -> right = newNode ( 14 ) ; int n1 = 10 , n2 = 14 ; node * t = lca ( root , n1 , n2 ) ; cout << " LCA ▁ of ▁ " << n1 << " ▁ and ▁ " << n2 << " ▁ is ▁ " << t -> data << endl ; n1 = 14 , n2 = 8 ; t = lca ( root , n1 , n2 ) ; cout << " LCA ▁ of ▁ " << n1 << " ▁ and ▁ " << n2 << " ▁ is ▁ " << t -> data << endl ; n1 = 10 , n2 = 22 ; t = lca ( root , n1 , n2 ) ; cout << " LCA ▁ of ▁ " << n1 << " ▁ and ▁ " << n2 << " ▁ is ▁ " << t -> data << endl ; return 0 ; }

Accumulator variables: stdc
Class/struct names: node
C++ program:
int isBST ( struct node * node ) { if ( node == NULL ) return 1 ; if ( node -> left != NULL && node -> left -> data > node -> data ) return 0 ; if ( node -> right != NULL && node -> right -> data < node -> data ) return 0 ; if ( ! isBST ( node -> left ) || ! isBST ( node -> right ) ) return 0 ; return 1 ; }

Class/struct names: node
C++ program:
int isBST ( struct node * node ) { if ( node == NULL ) return 1 ; if ( node -> left != NULL && maxValue ( node -> left ) > node -> data ) return 0 ; if ( node -> right != NULL && minValue ( node -> right ) < node -> data ) return 0 ; if ( ! isBST ( node -> left ) || ! isBST ( node -> right ) ) return 0 ; return 1 ; }

Class/struct names: node
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; bool isBST ( Node * root , Node * l = NULL , Node * r = NULL ) { if ( root == NULL ) return true ; if ( l != NULL and root -> data <= l -> data ) return false ; if ( r != NULL and root -> data >= r -> data ) return false ; return isBST ( root -> left , l , root ) and isBST ( root -> right , root , r ) ; } 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 ( 3 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 5 ) ; root -> left -> left = newNode ( 1 ) ; root -> left -> right = newNode ( 4 ) ; if ( isBST ( root , NULL , NULL ) ) cout << " Is ▁ BST " ; else cout << " Not ▁ a ▁ BST " ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * left , * right ; Node ( int data ) { this -> data = data ; left = right = NULL ; } } ; bool isBSTUtil ( struct Node * root , Node * & prev ) { if ( root ) { if ( ! isBSTUtil ( root -> left , prev ) ) return false ; if ( prev != NULL && root -> data <= prev -> data ) return false ; prev = root ; return isBSTUtil ( root -> right , prev ) ; } return true ; } bool isBST ( Node * root ) { Node * prev = NULL ; return isBSTUtil ( root , prev ) ; } int main ( ) { struct Node * root = new Node ( 3 ) ; root -> left = new Node ( 2 ) ; root -> right = new Node ( 5 ) ; root -> left -> left = new Node ( 1 ) ; root -> left -> right = new Node ( 4 ) ; if ( isBST ( root ) ) cout << " Is ▁ BST " ; else cout << " Not ▁ a ▁ BST " ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <iostream>
using namespace std ; struct Node { int data ; Node * left , * right ; Node ( int x ) { data = x ; left = right = NULL ; } } ; Node * insert ( Node * root , int x ) { if ( root == NULL ) return new Node ( x ) ; if ( x < root -> data ) root -> left = insert ( root -> left , x ) ; else if ( x > root -> data ) root -> right = insert ( root -> right , x ) ; return root ; } Node * kthSmallest ( Node * root , int & k ) { if ( root == NULL ) return NULL ; Node * left = kthSmallest ( root -> left , k ) ; if ( left != NULL ) return left ; k -- ; if ( k == 0 ) return root ; return kthSmallest ( root -> right , k ) ; } void printKthSmallest ( Node * root , int k ) { int count = 0 ; Node * res = kthSmallest ( root , k ) ; if ( res == NULL ) cout << " There ▁ are ▁ less ▁ than ▁ k ▁ nodes ▁ in ▁ the ▁ BST " ; else cout << " K - th ▁ Smallest ▁ Element ▁ is ▁ " << res -> data ; } int main ( ) { Node * root = NULL ; int keys [ ] = { 20 , 8 , 22 , 4 , 12 , 10 , 14 } ; for ( int x : keys ) root = insert ( root , x ) ; int k = 3 ; printKthSmallest ( root , k ) ; return 0 ; }

Accumulator variables: k
Iterator variables: x
Class/struct names: Node
C++ program:
#include <iostream>
using namespace std ; struct Node { int data ; Node * left , * right ; int lCount ; Node ( int x ) { data = x ; left = right = NULL ; lCount = 0 ; } } ; Node * insert ( Node * root , int x ) { if ( root == NULL ) return new Node ( x ) ; if ( x < root -> data ) { root -> left = insert ( root -> left , x ) ; root -> lCount ++ ; } else if ( x > root -> data ) root -> right = insert ( root -> right , x ) ; return root ; } Node * kthSmallest ( Node * root , int k ) { if ( root == NULL ) return NULL ; int count = root -> lCount + 1 ; if ( count == k ) return root ; if ( count > k ) return kthSmallest ( root -> left , k ) ; return kthSmallest ( root -> right , k - count ) ; } int main ( ) { Node * root = NULL ; int keys [ ] = { 20 , 8 , 22 , 4 , 12 , 10 , 14 } ; for ( int x : keys ) root = insert ( root , x ) ; int k = 4 ; Node * res = kthSmallest ( root , k ) ; if ( res == NULL ) cout << " There ▁ are ▁ less ▁ than ▁ k ▁ nodes ▁ in ▁ the ▁ BST " ; else cout << " K - th ▁ Smallest ▁ Element ▁ is ▁ " << res -> data ; return 0 ; }

Accumulator variables: lCount
Iterator variables: x
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { char data ; struct Node * left ; struct Node * right ; } ; struct Node * newNode ( char data ) { struct Node * node = new Node ; node -> data = data ; node -> left = node -> right = NULL ; return ( node ) ; } struct Node * buildTree ( char in [ ] , char pre [ ] , int inStrt , int inEnd , unordered_map < char , int > & mp ) { static int preIndex = 0 ; if ( inStrt > inEnd ) return NULL ; char curr = pre [ preIndex ++ ] ; struct Node * tNode = newNode ( curr ) ; if ( inStrt == inEnd ) return tNode ; int inIndex = mp [ curr ] ; tNode -> left = buildTree ( in , pre , inStrt , inIndex - 1 , mp ) ; tNode -> right = buildTree ( in , pre , inIndex + 1 , inEnd , mp ) ; return tNode ; } struct Node * buldTreeWrap ( char in [ ] , char pre [ ] , int len ) { unordered_map < char , int > mp ; for ( int i = 0 ; i < len ; i ++ ) mp [ in [ i ] ] = i ; return buildTree ( in , pre , 0 , len - 1 , mp ) ; } void printInorder ( struct Node * node ) { if ( node == NULL ) return ; printInorder ( node -> left ) ; printf ( " % c ▁ " , node -> data ) ; printInorder ( node -> right ) ; } int main ( ) { char in [ ] = { ' D ' , ' B ' , ' E ' , ' A ' , ' F ' , ' C ' } ; char pre [ ] = { ' A ' , ' B ' , ' D ' , ' E ' , ' C ' , ' F ' } ; int len = sizeof ( in ) / sizeof ( in [ 0 ] ) ; struct Node * root = buldTreeWrap ( in , pre , len ) ; printf ( " Inorder ▁ traversal ▁ of ▁ the ▁ constructed ▁ tree ▁ is ▁ STRNEWLINE " ) ; printInorder ( root ) ; }

Index/key variables: curr, i
Accumulator variables: i, preIndex, stdc
Iterator variables: i
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int key ; Node * left , * right ; } ; int KSmallestUsingMorris ( Node * root , int k ) { int count = 0 ; int ksmall = INT_MIN ; Node * curr = root ; while ( curr != NULL ) { if ( curr -> left == NULL ) { count ++ ; if ( count == k ) ksmall = curr -> key ; curr = curr -> right ; } else { Node * pre = curr -> left ; while ( pre -> right != NULL && pre -> right != curr ) pre = pre -> right ; if ( pre -> right == NULL ) { pre -> right = curr ; curr = curr -> left ; } else { pre -> right = NULL ; count ++ ; if ( count == k ) ksmall = curr -> key ; curr = curr -> right ; } } } return ksmall ; } Node * newNode ( int item ) { Node * temp = new Node ; temp -> key = item ; temp -> left = temp -> right = NULL ; return temp ; } Node * insert ( Node * node , int key ) { if ( node == NULL ) return newNode ( key ) ; if ( key < node -> key ) node -> left = insert ( node -> left , key ) ; else if ( key > node -> key ) node -> right = insert ( node -> right , key ) ; return node ; } int main ( ) { 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 ) ; for ( int k = 1 ; k <= 7 ; k ++ ) cout << KSmallestUsingMorris ( root , k ) << " ▁ " ; return 0 ; }

Accumulator variables: count, k, stdc
Iterator variables: k
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isInorder ( int arr [ ] , int n ) { if ( n == 0 n == 1 ) return true ; for ( int i = 1 ; i < n ; i ++ ) if ( arr [ i - 1 ] > arr [ i ] ) return false ; return true ; } int main ( ) { int arr [ ] = { 19 , 23 , 25 , 30 , 45 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; if ( isInorder ( arr , n ) ) cout << " Yesn " ; else cout << " Non " ; return 0 ; }

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