dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . * ; class Node { int data ; Node left , right ; public Node ( int data ) { this . data = data ; left = right = null ; } } class BinaryTree { Node root ; Node head ; void push ( Node node ) { node . right = head ; node . left = null ; if ( head != null ) head . left = node ; head = node ; } void printList ( Node node ) { while ( node != null ) { System . out . print ( node . data + " ▁ " ) ; node = node . right ; } } void spiralLevelOrder ( Node root ) { if ( root == null ) return ; Deque < Node > q = new LinkedList < Node > ( ) ; q . addFirst ( root ) ; Stack < Node > stk = new Stack < Node > ( ) ; int level = 0 ; while ( ! q . isEmpty ( ) ) { int nodeCount = q . size ( ) ; if ( ( level & 1 ) % 2 != 0 ) { while ( nodeCount > 0 ) { Node node = q . peekFirst ( ) ; q . pollFirst ( ) ; stk . push ( node ) ; if ( node . left != null ) q . addLast ( node . left ) ; if ( node . right != null ) q . addLast ( node . right ) ; nodeCount -- ; } } else { while ( nodeCount > 0 ) { Node node = q . peekLast ( ) ; q . pollLast ( ) ; stk . push ( node ) ; if ( node . right != null ) q . addFirst ( node . right ) ; if ( node . left != null ) q . addFirst ( node . left ) ; nodeCount -- ; } } level ++ ; } while ( ! stk . empty ( ) ) { push ( stk . peek ( ) ) ; stk . pop ( ) ; } System . out . println ( " Created ▁ DLL ▁ is ▁ : ▁ " ) ; printList ( head ) ; } 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 ) ; tree . root . right . left = new Node ( 6 ) ; tree . root . right . right = new Node ( 7 ) ; tree . root . left . left . left = new Node ( 8 ) ; tree . root . left . left . right = new Node ( 9 ) ; tree . root . left . right . left = new Node ( 10 ) ; tree . root . left . right . right = new Node ( 11 ) ; tree . root . right . left . right = new Node ( 13 ) ; tree . root . right . right . left = new Node ( 14 ) ; tree . spiralLevelOrder ( tree . root ) ; } }

Accumulator variables: level, nodeCount
Class/struct names: BinaryTree, Node
Java program:
import java . io . * ; import java . util . * ; class GFG { static void reverseWords ( String str ) { Stack < Character > st = new Stack < Character > ( ) ; for ( int i = 0 ; i < str . length ( ) ; ++ i ) { if ( str . charAt ( i ) != ' ▁ ' ) st . push ( str . charAt ( i ) ) ; else { while ( st . empty ( ) == false ) { System . out . print ( st . pop ( ) ) ; } System . out . print ( " ▁ " ) ; } } while ( st . empty ( ) == false ) { System . out . print ( st . pop ( ) ) ; } } public static void main ( String [ ] args ) { String str = " Geeks ▁ for ▁ Geeks " ; reverseWords ( str ) ; } }

Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int MAXN = 100005 ; static class pair { int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static void makeNext ( int arr [ ] , int n , int nextBig [ ] ) { Stack < pair > s = new Stack < > ( ) ; for ( int i = n - 1 ; i >= 0 ; i -- ) { nextBig [ i ] = i ; while ( ! s . empty ( ) && s . peek ( ) . first < arr [ i ] ) s . pop ( ) ; if ( ! s . empty ( ) ) nextBig [ i ] = s . peek ( ) . second ; s . push ( new pair ( arr [ i ] , i ) ) ; } } static void makePrev ( int arr [ ] , int n , int prevBig [ ] ) { Stack < pair > s = new Stack < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { prevBig [ i ] = - 1 ; while ( ! s . empty ( ) && s . peek ( ) . first < arr [ i ] ) s . pop ( ) ; if ( ! s . empty ( ) ) prevBig [ i ] = s . peek ( ) . second ; s . push ( new pair ( arr [ i ] , i ) ) ; } } static int wrapper ( int arr [ ] , int n ) { int [ ] nextBig = new int [ MAXN ] ; int [ ] prevBig = new int [ MAXN ] ; int [ ] maxi = new int [ MAXN ] ; int ans = 0 ; makePrev ( arr , n , prevBig ) ; makeNext ( arr , n , nextBig ) ; for ( int i = 0 ; i < n ; i ++ ) if ( nextBig [ i ] != i ) maxi [ nextBig [ i ] - i ] = Math . max ( maxi [ nextBig [ i ] - i ] , i - prevBig [ i ] ) ; for ( int i = 0 ; i < n ; i ++ ) ans += maxi [ i ] ; return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 2 , 4 } ; int n = arr . length ; System . out . println ( wrapper ( arr , n ) ) ; } }

Index/key variables: MAXN, i
Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG, pair
Java program:
import java . util . Stack ; public class RectArea { static int getMaxArea ( int hist [ ] , int n ) { Stack < Integer > s = new Stack < > ( ) ; int max_area = 0 ; int tp ; int area_with_top ; int i = 0 ; while ( i < n ) { if ( s . empty ( ) || hist [ s . peek ( ) ] <= hist [ i ] ) s . push ( i ++ ) ; else { tp = s . peek ( ) ; s . pop ( ) ; area_with_top = hist [ tp ] * ( s . empty ( ) ? i : i - s . peek ( ) - 1 ) ; if ( max_area < area_with_top ) max_area = area_with_top ; } } while ( s . empty ( ) == false ) { tp = s . peek ( ) ; s . pop ( ) ; area_with_top = hist [ tp ] * ( s . empty ( ) ? i : i - s . peek ( ) - 1 ) ; if ( max_area < area_with_top ) max_area = area_with_top ; } return max_area ; } public static void main ( String [ ] args ) { int hist [ ] = { 6 , 2 , 5 , 4 , 5 , 1 , 6 } ; System . out . println ( " Maximum ▁ area ▁ is ▁ " + getMaxArea ( hist , hist . length ) ) ; } }

Index/key variables: i, tp
Accumulator variables: i
Class/struct names: RectArea
Java program:
import java . util . * ; import java . io . * ; import java . math . * ; class GFG { static void towerOfHanoi ( int n , char from_rod , char to_rod , char aux_rod ) { if ( n == 1 ) { System . out . println ( " Move ▁ disk ▁ 1 ▁ from ▁ rod ▁ " + from_rod + " ▁ to ▁ rod ▁ " + to_rod ) ; return ; } towerOfHanoi ( n - 1 , from_rod , aux_rod , to_rod ) ; System . out . println ( " Move ▁ disk ▁ " + n + " ▁ from ▁ rod ▁ " + from_rod + " ▁ to ▁ rod ▁ " + to_rod ) ; towerOfHanoi ( n - 1 , aux_rod , to_rod , from_rod ) ; } public static void main ( String args [ ] ) { int n = 4 ; towerOfHanoi ( n , ' A ' , ' C ' , ' B ' ) ; } }

Class/struct names: GFG
Java program:
class Test { static int arr [ ] = { 10 , 20 , 30 , 50 , 10 , 70 , 30 } ; static void printMaxOfMin ( int n ) { for ( int k = 1 ; k <= n ; k ++ ) { int maxOfMin = Integer . MIN_VALUE ; for ( int i = 0 ; i <= n - k ; i ++ ) { int min = arr [ i ] ; for ( int j = 1 ; j < k ; j ++ ) { if ( arr [ i + j ] < min ) min = arr [ i + j ] ; } if ( min > maxOfMin ) maxOfMin = min ; } System . out . print ( maxOfMin + " ▁ " ) ; } } public static void main ( String [ ] args ) { printMaxOfMin ( arr . length ) ; } }

Index/key variables: i
Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: Test
Java program:
import java . util . Stack ; class Test { static int arr [ ] = { 10 , 20 , 30 , 50 , 10 , 70 , 30 } ; static void printMaxOfMin ( int n ) { Stack < Integer > s = new Stack < > ( ) ; int left [ ] = new int [ n + 1 ] ; int right [ ] = new int [ n + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) { left [ i ] = - 1 ; right [ i ] = n ; } for ( int i = 0 ; i < n ; i ++ ) { while ( ! s . empty ( ) && arr [ s . peek ( ) ] >= arr [ i ] ) s . pop ( ) ; if ( ! s . empty ( ) ) left [ i ] = s . peek ( ) ; s . push ( i ) ; } while ( ! s . empty ( ) ) s . pop ( ) ; for ( int i = n - 1 ; i >= 0 ; i -- ) { while ( ! s . empty ( ) && arr [ s . peek ( ) ] >= arr [ i ] ) s . pop ( ) ; if ( ! s . empty ( ) ) right [ i ] = s . peek ( ) ; s . push ( i ) ; } int ans [ ] = new int [ n + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) ans [ i ] = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int len = right [ i ] - left [ i ] - 1 ; ans [ len ] = Math . max ( ans [ len ] , arr [ i ] ) ; } for ( int i = n - 1 ; i >= 1 ; i -- ) ans [ i ] = Math . max ( ans [ i ] , ans [ i + 1 ] ) ; for ( int i = 1 ; i <= n ; i ++ ) System . out . print ( ans [ i ] + " ▁ " ) ; } public static void main ( String [ ] args ) { printMaxOfMin ( arr . length ) ; } }

Index/key variables: i, len
Accumulator variables: i
Iterator variables: i
Class/struct names: Test
Java program:
import java . util . * ; class GFG { static int N = 12 , ans ; static Vector < Vector < Integer > > tree = new Vector < Vector < Integer > > ( ) ; static int dfs ( int visit [ ] , int node ) { int num = 0 , temp = 0 ; visit [ node ] = 1 ; for ( int i = 0 ; i < tree . get ( node ) . size ( ) ; i ++ ) { if ( visit [ tree . get ( node ) . get ( i ) ] == 0 ) { temp = dfs ( visit , tree . get ( node ) . get ( i ) ) ; if ( temp % 2 != 0 ) num += temp ; else ans ++ ; } } return num + 1 ; } static int minEdge ( int n ) { int visit [ ] = new int [ n + 2 ] ; ans = 0 ; dfs ( visit , 1 ) ; return ans ; } public static void main ( String args [ ] ) { int n = 10 ; for ( int i = 0 ; i < n + 2 ; i ++ ) tree . add ( new Vector < Integer > ( ) ) ; tree . get ( 1 ) . add ( 3 ) ; tree . get ( 3 ) . add ( 1 ) ; tree . get ( 1 ) . add ( 6 ) ; tree . get ( 6 ) . add ( 1 ) ; tree . get ( 1 ) . add ( 2 ) ; tree . get ( 2 ) . add ( 1 ) ; tree . get ( 3 ) . add ( 4 ) ; tree . get ( 4 ) . add ( 3 ) ; tree . get ( 6 ) . add ( 8 ) ; tree . get ( 8 ) . add ( 6 ) ; tree . get ( 2 ) . add ( 7 ) ; tree . get ( 7 ) . add ( 2 ) ; tree . get ( 2 ) . add ( 5 ) ; tree . get ( 5 ) . add ( 2 ) ; tree . get ( 4 ) . add ( 9 ) ; tree . get ( 9 ) . add ( 4 ) ; tree . get ( 4 ) . add ( 10 ) ; tree . get ( 10 ) . add ( 4 ) ; System . out . println ( minEdge ( n ) ) ; } }

Index/key variables: node
Accumulator variables: ans, i, num
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . Stack ; public class GFG { static boolean checkRedundancy ( String s ) { Stack < Character > st = new Stack < > ( ) ; char [ ] str = s . toCharArray ( ) ; for ( char ch : str ) { if ( ch == ' ) ' ) { char top = st . peek ( ) ; st . pop ( ) ; boolean flag = true ; while ( top != ' ( ' ) { if ( top == ' + ' top == ' - ' top == ' * ' top == ' / ' ) { flag = false ; } top = st . peek ( ) ; st . pop ( ) ; } if ( flag == true ) { return true ; } } else { st . push ( ch ) ; } } return false ; } static void findRedundant ( String str ) { boolean ans = checkRedundancy ( str ) ; if ( ans == true ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } public static void main ( String [ ] args ) { String str = " ( ( a + b ) ) " ; findRedundant ( str ) ; str = " ( a + ( b ) / c ) " ; findRedundant ( str ) ; str = " ( a + b * ( c - d ) ) " ; findRedundant ( str ) ; } }

Iterator variables: ch
Boolean variables: flag
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static final int MAX_CHAR = 26 ; static boolean adjSign ( String s , int i ) { if ( i == 0 ) return true ; if ( s . charAt ( i - 1 ) == ' - ' ) return false ; return true ; } ; static void eval ( String s , int [ ] v , boolean add ) { Stack < Boolean > stk = new Stack < > ( ) ; stk . push ( true ) ; int i = 0 ; while ( i < s . length ( ) ) { if ( s . charAt ( i ) == ' + ' || s . charAt ( i ) == ' - ' ) { i ++ ; continue ; } if ( s . charAt ( i ) == ' ( ' ) { if ( adjSign ( s , i ) ) stk . push ( stk . peek ( ) ) ; else stk . push ( ! stk . peek ( ) ) ; } else if ( s . charAt ( i ) == ' ) ' ) stk . pop ( ) ; else { if ( stk . peek ( ) ) v [ s . charAt ( i ) - ' a ' ] += ( adjSign ( s , i ) ? add ? 1 : - 1 : add ? - 1 : 1 ) ; else v [ s . charAt ( i ) - ' a ' ] += ( adjSign ( s , i ) ? add ? - 1 : 1 : add ? 1 : - 1 ) ; } i ++ ; } } ; static boolean areSame ( String expr1 , String expr2 ) { int [ ] v = new int [ MAX_CHAR ] ; eval ( expr1 , v , true ) ; eval ( expr2 , v , false ) ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) if ( v [ i ] != 0 ) return false ; return true ; } public static void main ( String [ ] args ) { String expr1 = " - ( a + b + c ) " , expr2 = " - a - b - c " ; if ( areSame ( expr1 , expr2 ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Index/key variables: MAX_CHAR, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . Stack ; class GFG { static void test ( String expression , int index ) { int i ; if ( expression . charAt ( index ) != ' [ ' ) { System . out . print ( expression + " , ▁ " + index + ": -1NEW_LINE"); return ; } Stack < Integer > st = new Stack < > ( ) ; for ( i = index ; i < expression . length ( ) ; i ++ ) { if ( expression . charAt ( i ) == ' [ ' ) { st . push ( ( int ) expression . charAt ( i ) ) ; } else if ( expression . charAt ( i ) == ' ] ' ) { st . pop ( ) ; if ( st . empty ( ) ) { System . out . print ( expression + " , ▁ " + index + " : ▁ " + i + "NEW_LINE"); return ; } } } System . out . print ( expression + " , ▁ " + index + ": -1NEW_LINE"); } public static void main ( String [ ] args ) { test ( " [ ABC [ 23 ] ] [89 ] " , 0 ) ; test ( " [ ABC [ 23 ] ] [89 ] " , 4 ) ; test ( " [ ABC [ 23 ] ] [89 ] " , 9 ) ; test ( " [ ABC [ 23 ] ] [89 ] " , 1 ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GfG { static class Node { int data ; Node left ; Node right ; } static Node newNode ( int key ) { Node node = new Node ( ) ; node . data = key ; node . left = null ; node . right = null ; return node ; } static void convertTree ( Node root ) { if ( root == null ) return ; convertTree ( root . left ) ; convertTree ( root . right ) ; if ( root . left != null && root . right != null ) root . data = ( root . left . data ) & ( root . right . data ) ; } static void printInorder ( Node root ) { if ( root == null ) return ; printInorder ( root . left ) ; System . out . print ( root . data + " ▁ " ) ; printInorder ( root . right ) ; } public static void main ( String [ ] args ) { Node root = newNode ( 0 ) ; root . left = newNode ( 1 ) ; root . right = newNode ( 0 ) ; root . left . left = newNode ( 0 ) ; root . left . right = newNode ( 1 ) ; root . right . left = newNode ( 1 ) ; root . right . right = newNode ( 1 ) ; System . out . print ( " Inorder ▁ traversal ▁ before ▁ conversion ▁ " ) ; printInorder ( root ) ; convertTree ( root ) ; System . out . println ( ) ; System . out . print ( " Inorder ▁ traversal ▁ after ▁ conversion ▁ " ) ; printInorder ( root ) ; } }

Class/struct names: GfG, Node
Java program:
import java . util . Stack ; public class GFG { static boolean findDuplicateparenthesis ( String s ) { Stack < Character > Stack = new Stack < > ( ) ; char [ ] str = s . toCharArray ( ) ; for ( char ch : str ) { if ( ch == ' ) ' ) { char top = Stack . peek ( ) ; Stack . pop ( ) ; int elementsInside = 0 ; while ( top != ' ( ' ) { elementsInside ++ ; top = Stack . peek ( ) ; Stack . pop ( ) ; } if ( elementsInside < 1 ) { return true ; } } else { Stack . push ( ch ) ; } } return false ; } public static void main ( String [ ] args ) { String str = " ( ( ( a + ( b ) ) + ( c + d ) ) ) " ; if ( findDuplicateparenthesis ( str ) ) { System . out . println ( " Duplicate ▁ Found ▁ " ) ; } else { System . out . println ( " No ▁ Duplicates ▁ Found ▁ " ) ; } } }

Accumulator variables: elementsInside
Iterator variables: ch
Class/struct names: GFG
Java program:
import java . util . Stack ; public class Main { public static void nextGreater ( int arr [ ] , int next [ ] , char order ) { Stack < Integer > stack = new Stack < > ( ) ; for ( int i = arr . length - 1 ; i >= 0 ; i -- ) { while ( ! stack . isEmpty ( ) && ( ( order == ' G ' ) ? arr [ stack . peek ( ) ] <= arr [ i ] : arr [ stack . peek ( ) ] >= arr [ i ] ) ) stack . pop ( ) ; if ( ! stack . isEmpty ( ) ) next [ i ] = stack . peek ( ) ; else next [ i ] = - 1 ; stack . push ( i ) ; } } public static void nextSmallerOfNextGreater ( int arr [ ] ) { int NG [ ] = new int [ arr . length ] ; int RS [ ] = new int [ arr . length ] ; nextGreater ( arr , NG , ' G ' ) ; nextGreater ( arr , RS , ' S ' ) ; for ( int i = 0 ; i < arr . length ; i ++ ) { if ( NG [ i ] != - 1 && RS [ NG [ i ] ] != - 1 ) System . out . print ( arr [ RS [ NG [ i ] ] ] + " ▁ " ) ; else System . out . print ( " - 1 ▁ " ) ; } } public static void main ( String args [ ] ) { int arr [ ] = { 5 , 1 , 9 , 2 , 5 , 1 , 7 } ; nextSmallerOfNextGreater ( arr ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: Main
Java program:
import java . util . Queue ; import java . util . LinkedList ; class Node { char data ; Node left , right ; public Node ( char item ) { data = item ; left = null ; right = null ; } } class BinaryTree { Node convertExpression ( char [ ] expression , int i ) { if ( i >= expression . length ) return null ; Node root = new Node ( expression [ i ] ) ; ++ i ; if ( i < expression . length && expression [ i ] == ' ? ' ) root . left = convertExpression ( expression , i + 1 ) ; else if ( i < expression . length ) root . right = convertExpression ( expression , i + 1 ) ; return root ; } public void printTree ( Node root ) { if ( root == null ) return ; System . out . print ( root . data + " ▁ " ) ; printTree ( root . left ) ; printTree ( root . right ) ; } public static void main ( String args [ ] ) { String exp = " a ? b ? c : d : e " ; BinaryTree tree = new BinaryTree ( ) ; char [ ] expression = exp . toCharArray ( ) ; Node root = tree . convertExpression ( expression , 0 ) ; tree . printTree ( root ) ; } }

Index/key variables: i
Class/struct names: BinaryTree, Node
Java program:
import java . util . Stack ; class GFG { static int countNumber ( int n ) { int result = 0 ; Stack < Integer > s = new Stack < > ( ) ; for ( int i = 1 ; i <= 9 ; i ++ ) { if ( i <= n ) { s . push ( i ) ; result ++ ; } while ( ! s . empty ( ) ) { int tp = s . peek ( ) ; s . pop ( ) ; for ( int j = tp % 10 ; j <= 9 ; j ++ ) { int x = tp * 10 + j ; if ( x <= n ) { s . push ( x ) ; result ++ ; } } } } return result ; } public static void main ( String [ ] args ) { int n = 15 ; System . out . println ( countNumber ( n ) ) ; } }

Accumulator variables: i, j, result
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . Vector ; class Test { static int removeConsecutiveSame ( Vector < String > v ) { int n = v . size ( ) ; for ( int i = 0 ; i < n - 1 ; ) { if ( v . get ( i ) . equals ( v . get ( i + 1 ) ) ) { v . remove ( i ) ; v . remove ( i ) ; if ( i > 0 ) i -- ; n = n - 2 ; } else i ++ ; } return v . size ( ) ; } public static void main ( String [ ] args ) { Vector < String > v = new Vector < > ( ) ; v . addElement ( " tom " ) ; v . addElement ( " jerry " ) ; v . addElement ( " jerry " ) ; v . addElement ( " tom " ) ; System . out . println ( removeConsecutiveSame ( v ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: Test
Java program:
import java . util . Stack ; import java . util . Vector ; class Test { static int removeConsecutiveSame ( Vector < String > v ) { Stack < String > st = new Stack < > ( ) ; for ( int i = 0 ; i < v . size ( ) ; i ++ ) { if ( st . empty ( ) ) st . push ( v . get ( i ) ) ; else { String str = st . peek ( ) ; if ( str . equals ( v . get ( i ) ) ) st . pop ( ) ; else st . push ( v . get ( i ) ) ; } } return st . size ( ) ; } public static void main ( String [ ] args ) { Vector < String > v = new Vector < > ( ) ; v . addElement ( " ab " ) ; v . addElement ( " aa " ) ; v . addElement ( " aa " ) ; v . addElement ( " bcd " ) ; v . addElement ( " ab " ) ; System . out . println ( removeConsecutiveSame ( v ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: Test
Java program:
import java . util . Stack ; class Test { static String decode ( String str ) { Stack < Integer > integerstack = new Stack < > ( ) ; Stack < Character > stringstack = new Stack < > ( ) ; String temp = " " , result = " " ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { int count = 0 ; if ( Character . isDigit ( str . charAt ( i ) ) ) { while ( Character . isDigit ( str . charAt ( i ) ) ) { count = count * 10 + str . charAt ( i ) - '0' ; i ++ ; } i -- ; integerstack . push ( count ) ; } else if ( str . charAt ( i ) == ' ] ' ) { temp = " " ; count = 0 ; if ( ! integerstack . isEmpty ( ) ) { count = integerstack . peek ( ) ; integerstack . pop ( ) ; } while ( ! stringstack . isEmpty ( ) && stringstack . peek ( ) != ' [ ' ) { temp = stringstack . peek ( ) + temp ; stringstack . pop ( ) ; } if ( ! stringstack . empty ( ) && stringstack . peek ( ) == ' [ ' ) stringstack . pop ( ) ; for ( int j = 0 ; j < count ; j ++ ) result = result + temp ; for ( int j = 0 ; j < result . length ( ) ; j ++ ) stringstack . push ( result . charAt ( j ) ) ; result = " " ; } else if ( str . charAt ( i ) == ' [ ' ) { if ( Character . isDigit ( str . charAt ( i - 1 ) ) ) stringstack . push ( str . charAt ( i ) ) ; else { stringstack . push ( str . charAt ( i ) ) ; integerstack . push ( 1 ) ; } } else stringstack . push ( str . charAt ( i ) ) ; } while ( ! stringstack . isEmpty ( ) ) { result = stringstack . peek ( ) + result ; stringstack . pop ( ) ; } return result ; } public static void main ( String args [ ] ) { String str = "3 [ b2 [ ca ] ] " ; System . out . println ( decode ( str ) ) ; } }

Index/key variables: ca
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: Test
Java program:
import java . util . * ; class GfG { static class Node { int data ; Node left , right ; } static Node newNode ( int data ) { Node node = new Node ( ) ; node . data = data ; node . left = null ; node . right = null ; return node ; } static void printAncestors ( Node root , int key ) { if ( root == null ) return ; Stack < Node > st = new Stack < Node > ( ) ; while ( 1 == 1 ) { while ( root != null && root . data != key ) { st . push ( root ) ; root = root . left ; } if ( root != null && root . data == key ) break ; if ( st . peek ( ) . right == null ) { root = st . peek ( ) ; st . pop ( ) ; while ( ! st . isEmpty ( ) && st . peek ( ) . right == root ) { root = st . peek ( ) ; st . pop ( ) ; } } root = st . isEmpty ( ) ? null : st . peek ( ) . right ; } while ( ! st . isEmpty ( ) ) { System . out . print ( st . peek ( ) . data + " ▁ " ) ; st . pop ( ) ; } } public static void main ( String [ ] args ) { Node root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 7 ) ; root . left . left = newNode ( 3 ) ; root . left . right = newNode ( 5 ) ; root . right . left = newNode ( 8 ) ; root . right . right = newNode ( 9 ) ; root . left . left . left = newNode ( 4 ) ; root . left . right . right = newNode ( 6 ) ; root . right . right . left = newNode ( 10 ) ; int key = 6 ; printAncestors ( root , key ) ; } }

Class/struct names: GfG, Node
Java program:
import java . util . * ; class GfG { static class StackWithMax { static Stack < Integer > mainStack = new Stack < Integer > ( ) ; static Stack < Integer > trackStack = new Stack < Integer > ( ) ; static void push ( int x ) { mainStack . push ( x ) ; if ( mainStack . size ( ) == 1 ) { trackStack . push ( x ) ; return ; } if ( x > trackStack . peek ( ) ) trackStack . push ( x ) ; else trackStack . push ( trackStack . peek ( ) ) ; } static int getMax ( ) { return trackStack . peek ( ) ; } static void pop ( ) { mainStack . pop ( ) ; trackStack . pop ( ) ; } } ; public static void main ( String [ ] args ) { StackWithMax s = new StackWithMax ( ) ; s . push ( 20 ) ; System . out . println ( s . getMax ( ) ) ; s . push ( 10 ) ; System . out . println ( s . getMax ( ) ) ; s . push ( 50 ) ; System . out . println ( s . getMax ( ) ) ; } }

Class/struct names: GfG, StackWithMax
Java program:
import java . util . Stack ; public class GFG { static Stack < Integer > st = new Stack < > ( ) ; static void push_digits ( int number ) { while ( number != 0 ) { st . push ( number % 10 ) ; number = number / 10 ; } } static int reverse_number ( int number ) { push_digits ( number ) ; int reverse = 0 ; int i = 1 ; while ( ! st . isEmpty ( ) ) { reverse = reverse + ( st . peek ( ) * i ) ; st . pop ( ) ; i = i * 10 ; } return reverse ; } public static void main ( String [ ] args ) { int number = 39997 ; System . out . println ( reverse_number ( number ) ) ; } }

Class/struct names: GFG