dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . io . * ; import java . util . * ; class GFG { static void maxModProdSubarr ( int arr [ ] , int n , int M ) { int ans = 0 ; int length = n ; for ( int i = 0 ; i < n ; i ++ ) { int product = 1 ; for ( int j = i ; j < n ; j ++ ) { product = ( product * arr [ i ] ) % M ; if ( product > ans ) { ans = product ; if ( length > j - i + 1 ) { length = j - i + 1 ; } } } } System . out . println ( " Maximum ▁ subarray ▁ product ▁ is ▁ " + ans ) ; System . out . println ( " Minimum ▁ length ▁ of ▁ the ▁ maximum ▁ " + " product ▁ subarray ▁ is ▁ " + length ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 4 , 2 } ; int N = arr . length ; int M = 5 ; maxModProdSubarr ( arr , N , M ) ; } }

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int GCD ( int a , int b ) { return b == 0 ? a : GCD ( b , a % b ) ; } static boolean coprime ( int a , int b ) { if ( GCD ( a , b ) == 1 ) return true ; return false ; } static int numOfPairs ( ArrayList < String > arr , int N ) { int count = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { if ( coprime ( Integer . parseInt ( arr . get ( i ) ) , Integer . parseInt ( arr . get ( j ) ) ) ) { count = count + 1 ; } } } return count ; } static void noOfCoPrimePairs ( int N , int d1 , int d2 ) { ArrayList < String > l = new ArrayList < String > ( ) ; l . add ( Integer . toString ( d1 ) ) ; l . add ( Integer . toString ( d2 ) ) ; Collections . sort ( l ) ; if ( N < Integer . parseInt ( l . get ( 1 ) ) ) return ; ArrayList < String > total = new ArrayList < String > ( l ) ; ArrayList < String > temp2 = new ArrayList < String > ( l ) ; int flag = 0 ; ArrayList < String > temp3 = new ArrayList < String > ( l ) ; while ( l . get ( 0 ) . length ( ) < 10 ) { for ( int i = 0 ; i < l . size ( ) ; i ++ ) { for ( int j = 0 ; j < 2 ; j ++ ) { if ( Integer . parseInt ( l . get ( i ) + temp2 . get ( j ) ) > N ) { flag = 1 ; break ; } total . add ( l . get ( i ) + temp2 . get ( j ) ) ; temp3 . add ( l . get ( i ) + temp2 . get ( j ) ) ; } if ( flag == 1 ) break ; } if ( flag == 1 ) break ; l = temp3 ; temp3 . clear ( ) ; } int lenOfTotal = total . size ( ) ; int ans = numOfPairs ( total , lenOfTotal ) ; System . out . print ( ans ) ; } public static void main ( String args [ ] ) { int N = 30 , d1 = 2 , d2 = 3 ; noOfCoPrimePairs ( N , d1 , d2 ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void tile_placing ( int [ ] [ ] grid , int N ) { int dp [ ] = new int [ N + 5 ] ; Arrays . fill ( dp , 0 ) ; int orig_cost = 0 ; for ( int i = 0 ; i < 2 ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { orig_cost += grid [ i ] [ j ] ; } } dp [ 0 ] = 0 ; dp [ 1 ] = Math . abs ( grid [ 0 ] [ 0 ] - grid [ 1 ] [ 0 ] ) ; for ( int i = 2 ; i <= N ; i ++ ) { dp [ i ] = Math . max ( dp [ i - 1 ] + Math . abs ( grid [ 0 ] [ i - 1 ] - grid [ 1 ] [ i - 1 ] ) , dp [ i - 2 ] + Math . abs ( grid [ 0 ] [ i - 2 ] - grid [ 0 ] [ i - 1 ] ) + Math . abs ( grid [ 1 ] [ i - 2 ] - grid [ 1 ] [ i - 1 ] ) ) ; } System . out . println ( orig_cost - dp [ N ] ) ; } public static void main ( String [ ] args ) { int [ ] [ ] M = { { 7 , 5 , 1 , 3 } , { 8 , 6 , 0 , 2 } } ; int N = M [ 0 ] . length ; tile_placing ( M , N ) ; } }

Index/key variables: N, i, j
Accumulator variables: i, j, orig_cost
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void findSplit ( int arr [ ] , int N ) { for ( int l = 1 ; l <= N - 4 ; l ++ ) { for ( int r = l + 2 ; r <= N - 2 ; r ++ ) { int lsum = 0 , rsum = 0 , msum = 0 ; for ( int i = 0 ; i <= l - 1 ; i ++ ) { lsum += arr [ i ] ; } for ( int i = l + 1 ; i <= r - 1 ; i ++ ) { msum += arr [ i ] ; } for ( int i = r + 1 ; i < N ; i ++ ) { rsum += arr [ i ] ; } if ( lsum == rsum && rsum == msum ) { System . out . println ( l + " ▁ " + r ) ; return ; } } } System . out . print ( - 1 ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 5 , 12 , 7 , 19 , 4 , 3 } ; int N = arr . length ; findSplit ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: i, l, lsum, msum, r, rsum
Iterator variables: i, l, r
Class/struct names: GFG
Java program:
import java . util . * ; public class Main { static int solve ( int [ ] A , int n , int Q [ ] , int q ) { int one = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( A [ i ] == 1 ) one ++ ; int glows = 0 , count = 0 ; if ( one >= ( int ) Math . ceil ( n / 2 ) ) glows = 1 ; for ( int i = 0 ; i < q ; i ++ ) { int prev = glows ; if ( A [ Q [ i ] - 1 ] == 1 ) one -- ; if ( A [ Q [ i ] - 1 ] == 0 ) one ++ ; A [ Q [ i ] - 1 ] ^= 1 ; if ( one >= ( int ) Math . ceil ( n / 2.0 ) ) { glows = 1 ; } else { glows = 0 ; } if ( prev != glows ) count ++ ; } return count ; } public static void main ( String args [ ] ) { int n = 3 ; int arr [ ] = { 1 , 1 , 0 } ; int q = 3 ; int Q [ ] = { 3 , 2 , 1 } ; System . out . println ( solve ( arr , n , Q , q ) ) ; } }

Index/key variables: i
Accumulator variables: count, i, one
Iterator variables: i
Class/struct names: Main
Java program:
public class GFG { static int sumOfDigits ( int N ) { int sum = 0 ; while ( N != 0 ) { sum += N % 10 ; N /= 10 ; } return sum ; } static void elementsHavingDigitSumK ( int [ ] arr , int N , int K ) { int count = 0 ; for ( int i = 0 ; i < N ; ++ i ) { if ( sumOfDigits ( arr [ i ] ) == K ) { count ++ ; } } System . out . println ( count ) ; } public static void main ( String args [ ] ) { int [ ] arr = { 23 , 54 , 87 , 29 , 92 , 62 } ; int K = 11 ; int N = arr . length ; elementsHavingDigitSumK ( arr , N , K ) ; } }

Index/key variables: i
Accumulator variables: N, count, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static boolean isOperand ( char x ) { return ( x >= ' a ' && x <= ' z ' ) || ( x >= ' A ' && x <= ' Z ' ) ; } static String getInfix ( String exp ) { Stack < String > s = new Stack < String > ( ) ; for ( int i = 0 ; i < exp . length ( ) ; i ++ ) { if ( isOperand ( exp . charAt ( i ) ) ) { s . push ( exp . charAt ( i ) + " " ) ; } else { String op1 = s . peek ( ) ; s . pop ( ) ; String op2 = s . peek ( ) ; s . pop ( ) ; s . push ( " ( " + op2 + exp . charAt ( i ) + op1 + " ) " ) ; } } return s . peek ( ) ; } public static void main ( String args [ ] ) { String exp = " ab * c + " ; System . out . println ( getInfix ( exp ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GfG { static class node { int data ; node left , right ; } static int updatetree ( node root ) { if ( root == null ) return 0 ; if ( root . left == null && root . right == null ) return root . data ; int leftsum = updatetree ( root . left ) ; int rightsum = updatetree ( root . right ) ; root . data += leftsum ; return root . data + rightsum ; } static void inorder ( node node ) { if ( node == null ) return ; inorder ( node . left ) ; System . out . print ( node . data + " ▁ " ) ; inorder ( node . right ) ; } static node newNode ( int data ) { node node = new node ( ) ; node . data = data ; node . left = null ; node . right = null ; return ( node ) ; } public static void main ( String [ ] args ) { node root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 3 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 5 ) ; root . right . right = newNode ( 6 ) ; updatetree ( root ) ; System . out . println ( " Inorder ▁ traversal ▁ of ▁ the ▁ modified ▁ tree ▁ is " ) ; inorder ( root ) ; } }

Accumulator variables: data
Class/struct names: GfG, node
Java program:
import java . util . Arrays ; class GFG { static void calculateSpan ( int price [ ] , int n , int S [ ] ) { S [ 0 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { S [ i ] = 1 ; for ( int j = i - 1 ; ( j >= 0 ) && ( price [ i ] >= price [ j ] ) ; j -- ) S [ i ] ++ ; } } static void printArray ( int arr [ ] ) { System . out . print ( Arrays . toString ( arr ) ) ; } public static void main ( String [ ] args ) { int price [ ] = { 10 , 4 , 5 , 90 , 120 , 80 } ; int n = price . length ; int S [ ] = new int [ n ] ; calculateSpan ( price , n , S ) ; printArray ( S ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . Stack ; import java . util . Arrays ; public class GFG { static void calculateSpan ( int price [ ] , int n , int S [ ] ) { Stack < Integer > st = new Stack < > ( ) ; st . push ( 0 ) ; S [ 0 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { while ( ! st . empty ( ) && price [ st . peek ( ) ] <= price [ i ] ) st . pop ( ) ; S [ i ] = ( st . empty ( ) ) ? ( i + 1 ) : ( i - st . peek ( ) ) ; st . push ( i ) ; } } static void printArray ( int arr [ ] ) { System . out . print ( Arrays . toString ( arr ) ) ; } public static void main ( String [ ] args ) { int price [ ] = { 10 , 4 , 5 , 90 , 120 , 80 } ; int n = price . length ; int S [ ] = new int [ n ] ; calculateSpan ( price , n , S ) ; printArray ( S ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static void calculateSpan ( int A [ ] , int n , int ans [ ] ) { ans [ 0 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { int counter = 1 ; while ( ( i - counter ) >= 0 && A [ i ] >= A [ i - counter ] ) { counter += ans [ i - counter ] ; } ans [ i ] = counter ; } } static void printArray ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; } public static void main ( String [ ] args ) { int price [ ] = { 10 , 4 , 5 , 90 , 120 , 80 } ; int n = price . length ; int S [ ] = new int [ n ] ; calculateSpan ( price , n , S ) ; printArray ( S , n ) ; } }

Index/key variables: i, n
Accumulator variables: counter, i
Iterator variables: i
Class/struct names: GFG
Java program:
class Main { static void printNGE ( int arr [ ] , int n ) { int next , i , j ; for ( i = 0 ; i < n ; i ++ ) { next = - 1 ; for ( j = i + 1 ; j < n ; j ++ ) { if ( arr [ i ] < arr [ j ] ) { next = arr [ j ] ; break ; } } System . out . println ( arr [ i ] + " ▁ - - ▁ " + next ) ; } } public static void main ( String args [ ] ) { int arr [ ] = { 11 , 13 , 21 , 3 } ; int n = arr . length ; printNGE ( arr , n ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: Main
Java program:
class Node { int data ; Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } class BinaryTree { Node root ; void mirror ( ) { root = mirror ( root ) ; } Node mirror ( Node node ) { if ( node == null ) return node ; Node left = mirror ( node . left ) ; Node right = mirror ( node . right ) ; node . left = right ; node . right = left ; return node ; } void inOrder ( ) { inOrder ( root ) ; } void inOrder ( Node node ) { if ( node == null ) return ; inOrder ( node . left ) ; System . out . print ( node . data + " ▁ " ) ; inOrder ( node . right ) ; } public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . left . right = new Node ( 5 ) ; System . out . println ( " Inorder ▁ traversal ▁ of ▁ input ▁ tree ▁ is ▁ : " ) ; tree . inOrder ( ) ; System . out . println ( " " ) ; tree . mirror ( ) ; System . out . println ( " Inorder ▁ traversal ▁ of ▁ binary ▁ tree ▁ is ▁ : ▁ " ) ; tree . inOrder ( ) ; } }

Class/struct names: BinaryTree, Node
Java program:
import java . util . * ; class GFG { static void fillNext ( int next [ ] , int a [ ] , int n ) { Stack < Integer > s = new Stack < Integer > ( ) ; s . push ( 0 ) ; for ( int i = 1 ; i < n ; i ++ ) { while ( s . size ( ) > 0 ) { int cur = s . peek ( ) ; if ( a [ cur ] < a [ i ] ) { next [ cur ] = i ; s . pop ( ) ; } else break ; } s . push ( i ) ; } while ( s . size ( ) > 0 ) { int cur = s . peek ( ) ; next [ cur ] = - 1 ; s . pop ( ) ; } } static void count ( int a [ ] , int dp [ ] , int n ) { int next [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) next [ i ] = 0 ; fillNext ( next , a , n ) ; for ( int i = n - 2 ; i >= 0 ; i -- ) { if ( next [ i ] == - 1 ) dp [ i ] = 0 ; else dp [ i ] = 1 + dp [ next [ i ] ] ; } } static int answerQuery ( int dp [ ] , int index ) { return dp [ index ] ; } public static void main ( String args [ ] ) { int a [ ] = { 3 , 4 , 2 , 7 , 5 , 8 , 10 , 6 } ; int n = a . length ; int dp [ ] = new int [ n ] ; count ( a , dp , n ) ; System . out . println ( answerQuery ( dp , 3 ) ) ; System . out . println ( answerQuery ( dp , 6 ) ) ; System . out . println ( answerQuery ( dp , 1 ) ) ; } }

Index/key variables: cur, i, index, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static Vector < Integer > no_NGN ( int arr [ ] , int n ) { Vector < Integer > nxt = new Vector < > ( ) ; Stack < Integer > s = new Stack < > ( ) ; nxt . add ( 0 ) ; s . add ( n - 1 ) ; for ( int i = n - 2 ; i >= 0 ; i -- ) { while ( ! s . isEmpty ( ) && arr [ i ] >= arr [ s . peek ( ) ] ) s . pop ( ) ; if ( s . isEmpty ( ) ) nxt . add ( 0 ) ; else nxt . add ( nxt . get ( n - s . peek ( ) - 1 ) + 1 ) ; s . add ( i ) ; } Collections . reverse ( nxt ) ; return nxt ; } public static void main ( String [ ] args ) { int n = 8 ; int arr [ ] = { 3 , 4 , 2 , 7 , 5 , 8 , 10 , 6 } ; Vector < Integer > nxt = no_NGN ( arr , n ) ; System . out . print ( nxt . get ( 3 ) + "NEW_LINE"); System . out . print ( nxt . get ( 6 ) + "NEW_LINE"); System . out . print ( nxt . get ( 1 ) + "NEW_LINE"); } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int MAX = 1000 ; static int [ ] nextGreaterInLeft ( int [ ] a , int n ) { int [ ] left_index = new int [ MAX ] ; Stack < Integer > s = new Stack < Integer > ( ) ; for ( int i = n - 1 ; i >= 0 ; i -- ) { while ( s . size ( ) != 0 && a [ i ] > a [ s . peek ( ) - 1 ] ) { int r = s . peek ( ) ; s . pop ( ) ; left_index [ r - 1 ] = i + 1 ; } s . push ( i + 1 ) ; } return left_index ; } static int [ ] nextGreaterInRight ( int [ ] a , int n ) { int [ ] right_index = new int [ MAX ] ; Stack < Integer > s = new Stack < Integer > ( ) ; for ( int i = 0 ; i < n ; ++ i ) { while ( s . size ( ) != 0 && a [ i ] > a [ s . peek ( ) - 1 ] ) { int r = s . peek ( ) ; s . pop ( ) ; right_index [ r - 1 ] = i + 1 ; } s . push ( i + 1 ) ; } return right_index ; } static int LRProduct ( int [ ] arr , int n ) { int [ ] left = nextGreaterInLeft ( arr , n ) ; int [ ] right = nextGreaterInRight ( arr , n ) ; int ans = - 1 ; for ( int i = 1 ; i <= n ; i ++ ) { ans = Math . max ( ans , left [ i ] * right [ i ] ) ; } return ans ; } public static void main ( String args [ ] ) { int [ ] arr = new int [ ] { 5 , 4 , 3 , 4 , 5 } ; int n = arr . length ; System . out . print ( LRProduct ( arr , n ) ) ; } }

Index/key variables: MAX, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static final int N = 8 ; static int MATRIX [ ] [ ] = { { 0 , 0 , 1 , 0 } , { 0 , 0 , 1 , 0 } , { 0 , 0 , 0 , 0 } , { 0 , 0 , 1 , 0 } } ; static int knows ( int a , int b ) { return MATRIX [ a ] [ b ] ; } static int findCelebrity ( int n ) { int [ ] indegree = new int [ n ] ; int [ ] outdegree = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { int x = knows ( i , j ) ; outdegree [ i ] += x ; indegree [ j ] += x ; } } for ( int i = 0 ; i < n ; i ++ ) if ( indegree [ i ] == n - 1 && outdegree [ i ] == 0 ) return i ; return - 1 ; } public static void main ( String [ ] args ) { int n = 4 ; int id = findCelebrity ( n ) ; if ( id == - 1 ) System . out . print ( " No ▁ celebrity " ) ; else System . out . print ( " Celebrity ▁ ID ▁ " + id ) ; } }

Index/key variables: a, b, i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . Stack ; public class EvaluateString { public static boolean hasPrecedence ( char op1 , char op2 ) { if ( op2 == ' ( ' op2 == ' ) ' ) return false ; if ( ( op1 == ' * ' op1 == ' / ' ) && ( op2 == ' + ' op2 == ' - ' ) ) return false ; else return true ; } public static int applyOp ( char op , int b , int a ) { switch ( op ) { case ' + ' : return a + b ; case ' - ' : return a - b ; case ' * ' : return a * b ; case ' / ' : if ( b == 0 ) throw new UnsupportedOperationException ( " Cannot ▁ divide ▁ by ▁ zero " ) ; return a / b ; } return 0 ; } public static int evaluate ( String expression ) { char [ ] tokens = expression . toCharArray ( ) ; Stack < Integer > values = new Stack < Integer > ( ) ; Stack < Character > ops = new Stack < Character > ( ) ; for ( int i = 0 ; i < tokens . length ; i ++ ) { if ( tokens [ i ] == ' ▁ ' ) continue ; else if ( tokens [ i ] == ' ( ' ) ops . push ( tokens [ i ] ) ; if ( tokens [ i ] >= '0' && tokens [ i ] <= '9' ) { StringBuffer sbuf = new StringBuffer ( ) ; while ( i < tokens . length && tokens [ i ] >= '0' && tokens [ i ] <= '9' ) sbuf . append ( tokens [ i ++ ] ) ; values . push ( Integer . parseInt ( sbuf . toString ( ) ) ) ; i -- ; } else if ( tokens [ i ] == ' ) ' ) { while ( ops . peek ( ) != ' ( ' ) values . push ( applyOp ( ops . pop ( ) , values . pop ( ) , values . pop ( ) ) ) ; ops . pop ( ) ; } else if ( tokens [ i ] == ' + ' tokens [ i ] == ' - ' tokens [ i ] == ' * ' tokens [ i ] == ' / ' ) { while ( ! ops . empty ( ) && hasPrecedence ( tokens [ i ] , ops . peek ( ) ) ) values . push ( applyOp ( ops . pop ( ) , values . pop ( ) , values . pop ( ) ) ) ; ops . push ( tokens [ i ] ) ; } } while ( ! ops . empty ( ) ) values . push ( applyOp ( ops . pop ( ) , values . pop ( ) , values . pop ( ) ) ) ; return values . pop ( ) ; } public static void main ( String [ ] args ) { System . out . println ( EvaluateString . evaluate ( "10 ▁ + ▁ 2 ▁ * ▁ 6" ) ) ; System . out . println ( EvaluateString . evaluate ( "100 ▁ * ▁ 2 ▁ + ▁ 12" ) ) ; System . out . println ( EvaluateString . evaluate ( "100 ▁ * ▁ ( ▁ 2 ▁ + ▁ 12 ▁ ) " ) ) ; System . out . println ( EvaluateString . evaluate ( "100 ▁ * ▁ ( ▁ 2 ▁ + ▁ 12 ▁ ) ▁ / ▁ 14" ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: EvaluateString
Java program:
import java . util . * ; class GFG { static class Node { int data ; Node left ; Node right ; } ; static Node newNode ( int data ) { Node node = new Node ( ) ; node . data = data ; node . left = node . right = null ; return ( node ) ; } static void mirror ( Node root ) { if ( root == null ) return ; Queue < Node > q = new LinkedList < > ( ) ; q . add ( root ) ; while ( q . size ( ) > 0 ) { Node curr = q . peek ( ) ; q . remove ( ) ; Node temp = curr . left ; curr . left = curr . right ; curr . right = temp ; ; if ( curr . left != null ) q . add ( curr . left ) ; if ( curr . right != null ) q . add ( curr . right ) ; } } static void inOrder ( Node node ) { if ( node == null ) return ; inOrder ( node . left ) ; System . out . print ( node . data + " ▁ " ) ; inOrder ( node . right ) ; } public static void main ( String args [ ] ) { Node root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 3 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 5 ) ; System . out . print ( " Inorder traversal of the " ▁ + " coned tree is "); inOrder ( root ) ; mirror ( root ) ; System . out . print ( " Inorder traversal of the " + ▁ " mirror tree is "); inOrder ( root ) ; } }

Class/struct names: GFG, Node
Java program:
class TOH { class Stack { int capacity ; int top ; int array [ ] ; } Stack createStack ( int capacity ) { Stack stack = new Stack ( ) ; stack . capacity = capacity ; stack . top = - 1 ; stack . array = new int [ capacity ] ; return stack ; } boolean isFull ( Stack stack ) { return ( stack . top == stack . capacity - 1 ) ; } boolean isEmpty ( Stack stack ) { return ( stack . top == - 1 ) ; } void push ( Stack stack , int item ) { if ( isFull ( stack ) ) return ; stack . array [ ++ stack . top ] = item ; } int pop ( Stack stack ) { if ( isEmpty ( stack ) ) return Integer . MIN_VALUE ; return stack . array [ stack . top -- ] ; } void moveDisk ( char fromPeg , char toPeg , int disk ) { System . out . println ( " Move ▁ the ▁ disk ▁ " + disk + " ▁ from ▁ " + fromPeg + " ▁ to ▁ " + toPeg ) ; } void moveDisksBetweenTwoPoles ( Stack src , Stack dest , char s , char d ) { int pole1TopDisk = pop ( src ) ; int pole2TopDisk = pop ( dest ) ; if ( pole1TopDisk == Integer . MIN_VALUE ) { push ( src , pole2TopDisk ) ; moveDisk ( d , s , pole2TopDisk ) ; } else if ( pole2TopDisk == Integer . MIN_VALUE ) { push ( dest , pole1TopDisk ) ; moveDisk ( s , d , pole1TopDisk ) ; } else if ( pole1TopDisk > pole2TopDisk ) { push ( src , pole1TopDisk ) ; push ( src , pole2TopDisk ) ; moveDisk ( d , s , pole2TopDisk ) ; } else { push ( dest , pole2TopDisk ) ; push ( dest , pole1TopDisk ) ; moveDisk ( s , d , pole1TopDisk ) ; } } void tohIterative ( int num_of_disks , Stack src , Stack aux , Stack dest ) { int i , total_num_of_moves ; char s = ' S ' , d = ' D ' , a = ' A ' ; if ( num_of_disks % 2 == 0 ) { char temp = d ; d = a ; a = temp ; } total_num_of_moves = ( int ) ( Math . pow ( 2 , num_of_disks ) - 1 ) ; for ( i = num_of_disks ; i >= 1 ; i -- ) push ( src , i ) ; for ( i = 1 ; i <= total_num_of_moves ; i ++ ) { if ( i % 3 == 1 ) moveDisksBetweenTwoPoles ( src , dest , s , d ) ; else if ( i % 3 == 2 ) moveDisksBetweenTwoPoles ( src , aux , s , a ) ; else if ( i % 3 == 0 ) moveDisksBetweenTwoPoles ( aux , dest , a , d ) ; } } public static void main ( String [ ] args ) { int num_of_disks = 3 ; TOH ob = new TOH ( ) ; Stack src , dest , aux ; src = ob . createStack ( num_of_disks ) ; dest = ob . createStack ( num_of_disks ) ; aux = ob . createStack ( num_of_disks ) ; ob . tohIterative ( num_of_disks , src , aux , dest ) ; } }

Index/key variables: capacity
Accumulator variables: i, top
Iterator variables: i
Class/struct names: Stack, TOH
Java program:
import java . io . * ; import java . util . * ; public class GFG { static void deleteMid ( Stack < Character > st , int n , int curr ) { if ( st . empty ( ) curr == n ) return ; char x = st . pop ( ) ; deleteMid ( st , n , curr + 1 ) ; if ( curr != n / 2 ) st . push ( x ) ; } public static void main ( String args [ ] ) { Stack < Character > st = new Stack < Character > ( ) ; st . push ( '1' ) ; st . push ( '2' ) ; st . push ( '3' ) ; st . push ( '4' ) ; st . push ( '5' ) ; st . push ( '6' ) ; st . push ( '7' ) ; deleteMid ( st , st . size ( ) , 0 ) ; while ( ! st . empty ( ) ) { char p = st . pop ( ) ; System . out . print ( p + " ▁ " ) ; } } }

Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static Stack < Integer > sortStack ( Stack < Integer > input ) { Stack < Integer > tmpStack = new Stack < Integer > ( ) ; while ( ! input . empty ( ) ) { int tmp = input . peek ( ) ; input . pop ( ) ; while ( ! tmpStack . empty ( ) && tmpStack . peek ( ) < tmp ) { input . push ( tmpStack . peek ( ) ) ; tmpStack . pop ( ) ; } tmpStack . push ( tmp ) ; } return tmpStack ; } static void sortArrayUsingStacks ( int [ ] arr , int n ) { Stack < Integer > input = new Stack < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) input . push ( arr [ i ] ) ; Stack < Integer > tmpStack = sortStack ( input ) ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = tmpStack . peek ( ) ; tmpStack . pop ( ) ; } } public static void main ( String args [ ] ) { int [ ] arr = { 10 , 5 , 15 , 45 } ; int n = arr . length ; sortArrayUsingStacks ( arr , n ) ; for ( int i = 0 ; i < n ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG