dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
var head = null ; class Node { constructor ( val ) { this . val = val ; this . next = null ; } } function insert ( data ) { var new_node = new Node ( data ) ; new_node . next = head ; head = new_node ; } function removeAllDuplicates ( ) { var dummy = new Node ( 0 ) ; dummy . next = head ; var prev = dummy ; var current = head ; while ( current != null ) { while ( current . next != null && prev . next . val == current . next . val ) current = current . next ; if ( prev . next == current ) prev = prev . next ; else prev . next = current . next ; current = current . next ; } head = dummy . next ; } function printList ( ) { var trav = head ; if ( head == null ) document . write ( " " ) ; while ( trav != null ) { document . write ( trav . val + " " ) ; trav = trav . next ; } } insert ( 53 ) ; insert ( 53 ) ; insert ( 49 ) ; insert ( 49 ) ; insert ( 35 ) ; insert ( 28 ) ; insert ( 28 ) ; insert ( 23 ) ; document . write ( " " ) ; printList ( ) ; removeAllDuplicates ( ) ; document . write ( " " ) ; printList ( ) ;

Class/struct names: Node
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } function freeList ( node ) { while ( node != null ) { next = node . next ; node = next ; } return node ; } function deleteKthNode ( head , k ) { if ( head == null ) return null ; if ( k == 1 ) { head = freeList ( head ) ; return null ; } var ptr = head , prev = null ; var count = 0 ; while ( ptr != null ) { count ++ ; if ( k == count ) { prev . next = ptr . next ; count = 0 ; } if ( count != 0 ) prev = ptr ; ptr = prev . next ; } return head ; } function displayList ( head ) { temp = head ; while ( temp != null ) { document . write ( temp . data + " " ) ; temp = temp . next ; } } function newNode ( x ) { temp = new Node ( ) ; temp . data = x ; temp . next = null ; return temp ; } 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 ) ; head . next . next . next . next . next = newNode ( 6 ) ; head . next . next . next . next . next . next = newNode ( 7 ) ; head . next . next . next . next . next . next . next = newNode ( 8 ) ; var k = 3 ; head = deleteKthNode ( head , k ) ; displayList ( head ) ;

Accumulator variables: count
Class/struct names: Node
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } function LinkedListLength ( head ) { while ( head != null && head . next != null ) { head = head . next . next ; } if ( head == null ) return 0 ; return 1 ; } function push ( head , info ) { node = new Node ( ) ; node . data = info ; node . next = ( head ) ; ( head ) = node ; } head = null ; push ( head , 4 ) ; push ( head , 5 ) ; push ( head , 7 ) ; push ( head , 2 ) ; push ( head , 9 ) ; push ( head , 6 ) ; push ( head , 1 ) ; push ( head , 2 ) ; push ( head , 0 ) ; push ( head , 5 ) ; push ( head , 5 ) ; var check = LinkedListLength ( head ) ; if ( check == 0 ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Class/struct names: Node
Javascript program:
class Node { constructor ( ) { let data , next ; } } function push ( head_ref , new_data ) { let new_node = new Node ( ) ; new_node . data = new_data ; new_node . next = head_ref ; head_ref = new_node ; return head_ref ; } function sumOfLastN_NodesUtil ( head , n ) { if ( n <= 0 ) return 0 ; let st = [ ] ; let sum = 0 ; while ( head != null ) { st . push ( head . data ) ; head = head . next ; } while ( n -- > 0 ) { sum += st [ st . length - 1 ] ; st . pop ( ) ; } return sum ; } let head = null ; head = push ( head , 12 ) ; head = push ( head , 4 ) ; head = push ( head , 8 ) ; head = push ( head , 6 ) ; head = push ( head , 10 ) ; let n = 2 ; document . write ( " " + n + " " + sumOfLastN_NodesUtil ( head , n ) ) ;

Accumulator variables: n, sum
Class/struct names: Node
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } var head ; function push ( head_ref , new_data ) { var new_node = new Node ( ) ; new_node . data = new_data ; new_node . next = head_ref ; head_ref = new_node ; head = head_ref ; } function reverseList ( head_ref ) { var current , prev , next ; current = head_ref ; prev = null ; while ( current != null ) { next = current . next ; current . next = prev ; prev = current ; current = next ; } head_ref = prev ; head = head_ref ; } function sumOfLastN_NodesUtil ( n ) { if ( n <= 0 ) return 0 ; reverseList ( head ) ; var sum = 0 ; var current = head ; while ( current != null && n -- > 0 ) { sum += current . data ; current = current . next ; } reverseList ( head ) ; return sum ; } push ( head , 12 ) ; push ( head , 4 ) ; push ( head , 8 ) ; push ( head , 6 ) ; push ( head , 10 ) ; var n = 2 ; document . write ( " " + n + " " + sumOfLastN_NodesUtil ( n ) ) ;

Accumulator variables: n, sum
Class/struct names: Node
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } var head ; function push ( head_ref , new_data ) { new_node = new Node ( ) ; new_node . data = new_data ; new_node . next = head_ref ; head_ref = new_node ; head = head_ref ; } function sumOfLastN_NodesUtil ( head , n ) { if ( n <= 0 ) return 0 ; var sum = 0 , len = 0 ; temp = head ; while ( temp != null ) { len ++ ; temp = temp . next ; } var c = len - n ; temp = head ; while ( temp != null && c -- > 0 ) { temp = temp . next ; } while ( temp != null ) { sum += temp . data ; temp = temp . next ; } return sum ; } push ( head , 12 ) ; push ( head , 4 ) ; push ( head , 8 ) ; push ( head , 6 ) ; push ( head , 10 ) ; var n = 2 ; document . write ( " " + n + " " + sumOfLastN_NodesUtil ( head , n ) ) ;

Accumulator variables: c, len, sum
Class/struct names: Node
Javascript program:
class Node { constructor ( key ) { this . data = key ; this . next = null ; } } let head ; let temp ; function printList ( node ) { while ( node != null ) { document . write ( node . data + " " ) ; node = node . next ; } document . write ( " " ) ; } function mergeKLists ( arr , last ) { for ( let i = 1 ; i <= last ; i ++ ) { while ( true ) { let head_0 = arr [ 0 ] ; let head_i = arr [ i ] ; if ( head_i == null ) break ; if ( head_0 . data >= head_i . data ) { arr [ i ] = head_i . next ; head_i . next = head_0 ; arr [ 0 ] = head_i ; } else { while ( head_0 . next != null ) { if ( head_0 . next . data >= head_i . data ) { arr [ i ] = head_i . next ; head_i . next = head_0 . next ; head_0 . next = head_i ; break ; } head_0 = head_0 . next ; if ( head_0 . next == null ) { arr [ i ] = head_i . next ; head_i . next = null ; head_0 . next = head_i ; head_0 . next . next = null ; break ; } } } } } return arr [ 0 ] ; } let k = 3 ; let n = 4 ; let arr = new Array ( k ) ; arr [ 0 ] = new Node ( 1 ) ; arr [ 0 ] . next = new Node ( 3 ) ; arr [ 0 ] . next . next = new Node ( 5 ) ; arr [ 0 ] . next . next . next = new Node ( 7 ) ; arr [ 1 ] = new Node ( 2 ) ; arr [ 1 ] . next = new Node ( 4 ) ; arr [ 1 ] . next . next = new Node ( 6 ) ; arr [ 1 ] . next . next . next = new Node ( 8 ) ; arr [ 2 ] = new Node ( 0 ) ; arr [ 2 ] . next = new Node ( 9 ) ; arr [ 2 ] . next . next = new Node ( 10 ) ; arr [ 2 ] . next . next . next = new Node ( 11 ) ; head = mergeKLists ( arr , k - 1 ) ; printList ( head ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: Node
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } function newNode ( key ) { temp = new Node ( ) ; temp . data = key ; temp . next = null ; return temp ; } function printList ( node ) { while ( node != null ) { document . write ( node . data + " " ) ; node = node . next ; } } function merge ( h1 , h2 ) { if ( h1 == null ) return h2 ; if ( h2 == null ) return h1 ; if ( h1 . data < h2 . data ) { h1 . next = merge ( h1 . next , h2 ) ; return h1 ; } else { h2 . next = merge ( h1 , h2 . next ) ; return h2 ; } } head1 = newNode ( 1 ) ; head1 . next = newNode ( 3 ) ; head1 . next . next = newNode ( 5 ) ; head2 = newNode ( 0 ) ; head2 . next = newNode ( 2 ) ; head2 . next . next = newNode ( 4 ) ; mergedhead = merge ( head1 , head2 ) ; printList ( mergedhead ) ;

Class/struct names: Node
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } function newNode ( key ) { var temp = new Node ( ) ; temp . data = key ; temp . next = null ; return temp ; } function printList ( node ) { while ( node != null ) { document . write ( node . data + " " ) ; node = node . next ; } } function mergeUtil ( h1 , h2 ) { if ( h1 . next == null ) { h1 . next = h2 ; return h1 ; } var curr1 = h1 , next1 = h1 . next ; var curr2 = h2 , next2 = h2 . next ; while ( next1 != null && curr2 != null ) { if ( ( curr2 . data ) >= ( curr1 . data ) && ( curr2 . data ) <= ( next1 . data ) ) { next2 = curr2 . next ; curr1 . next = curr2 ; curr2 . next = next1 ; curr1 = curr2 ; curr2 = next2 ; } else { if ( next1 . next != null ) { next1 = next1 . next ; curr1 = curr1 . next ; } else { next1 . next = curr2 ; return h1 ; } } } return h1 ; } function merge ( h1 , h2 ) { if ( h1 == null ) return h2 ; if ( h2 == null ) return h1 ; if ( h1 . data < h2 . data ) return mergeUtil ( h1 , h2 ) ; else return mergeUtil ( h2 , h1 ) ; } var head1 = newNode ( 1 ) ; head1 . next = newNode ( 3 ) ; head1 . next . next = newNode ( 5 ) ; var head2 = newNode ( 0 ) ; head2 . next = newNode ( 2 ) ; head2 . next . next = newNode ( 4 ) ; var mergedhead = merge ( head1 , head2 ) ; printList ( mergedhead ) ;

Class/struct names: Node
Javascript program:
class Node { constructor ( val ) { this . data = val ; this . next = null ; } } function swapNodes ( head_ref , currX , currY , prevY ) { head_ref = currY ; prevY . next = currX ; var temp = currY . next ; currY . next = currX . next ; currX . next = temp ; return head_ref ; } function recurSelectionSort ( head ) { if ( head . next == null ) return head ; var min = head ; var beforeMin = null ; var ptr ; for ( ptr = head ; ptr . next != null ; ptr = ptr . next ) { if ( ptr . next . data < min . data ) { min = ptr . next ; beforeMin = ptr ; } } if ( min != head ) head = swapNodes ( head , head , min , beforeMin ) ; head . next = recurSelectionSort ( head . next ) ; return head ; } function sort ( head_ref ) { if ( ( head_ref ) == null ) return null ; head_ref = recurSelectionSort ( head_ref ) ; return head_ref ; } function push ( head_ref , new_data ) { var new_node = new Node ( ) ; new_node . data = new_data ; new_node . next = ( head_ref ) ; ( head_ref ) = new_node ; return head_ref ; } function printList ( head ) { while ( head != null ) { document . write ( head . data + " " ) ; head = head . next ; } } var head = null ; head = push ( head , 6 ) ; head = push ( head , 4 ) ; head = push ( head , 8 ) ; head = push ( head , 12 ) ; head = push ( head , 10 ) ; document . write ( " " ) ; printList ( head ) ; head = sort ( head ) ; document . write ( " " ) ; printList ( head ) ;

Iterator variables: ptr
Class/struct names: Node
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } function getNode ( data ) { var newNode = new Node ( ) ; newNode . data = data ; newNode . next = null ; return newNode ; } function insertAfterNthNode ( head , n , x ) { if ( head == null ) return ; var newNode = getNode ( x ) ; var ptr = head ; var len = 0 , i ; while ( ptr != null ) { len ++ ; ptr = ptr . next ; } ptr = head ; for ( i = 1 ; i <= ( len - n ) ; i ++ ) ptr = ptr . next ; newNode . next = ptr . next ; ptr . next = newNode ; } function printList ( head ) { while ( head != null ) { document . write ( head . data + " " ) ; head = head . next ; } } var head = getNode ( 1 ) ; head . next = getNode ( 3 ) ; head . next . next = getNode ( 4 ) ; head . next . next . next = getNode ( 5 ) ; var n = 4 , x = 2 ; document . write ( " " ) ; printList ( head ) ; insertAfterNthNode ( head , n , x ) ; document . write ( ) ; document . write ( " " ) ; printList ( head ) ;

Accumulator variables: i, len
Iterator variables: i
Class/struct names: Node
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } function getNode ( data ) { var newNode = new Node ( ) ; newNode . data = data ; newNode . next = null ; return newNode ; } function insertAfterNthNode ( head , n , x ) { if ( head == null ) return ; var newNode = getNode ( x ) ; var slow_ptr = head ; var fast_ptr = head ; for ( var i = 1 ; i <= n - 1 ; i ++ ) fast_ptr = fast_ptr . next ; while ( fast_ptr . next != null ) { slow_ptr = slow_ptr . next ; fast_ptr = fast_ptr . next ; } newNode . next = slow_ptr . next ; slow_ptr . next = newNode ; } function printList ( head ) { while ( head != null ) { document . write ( head . data + " " ) ; head = head . next ; } } var head = getNode ( 1 ) ; head . next = getNode ( 3 ) ; head . next . next = getNode ( 4 ) ; head . next . next . next = getNode ( 5 ) ; var n = 4 , x = 2 ; document . write ( " " ) ; printList ( head ) ; insertAfterNthNode ( head , n , x ) ; document . write ( " " ) ; document . write ( " " ) ; printList ( head ) ;

Accumulator variables: i
Iterator variables: i
Class/struct names: Node
Javascript program:
class Node { constructor ( val ) { this . data = val ; this . next = null ; } } var head ; function setMiddleHead ( ) { if ( head == null ) return ; one_node = head ; two_node = head ; prev = null ; while ( two_node != null && two_node . next != null ) { prev = one_node ; two_node = two_node . next . next ; one_node = one_node . next ; } prev . next = prev . next . next ; one_node . next = head ; head = one_node ; } function push ( new_data ) { new_node = new Node ( new_data ) ; new_node . next = head ; head = new_node ; } function printList ( ptr ) { while ( ptr != null ) { document . write ( ptr . data + " " ) ; ptr = ptr . next ; } document . write ( " " ) ; } head = null ; var i ; for ( i = 5 ; i > 0 ; i -- ) push ( i ) ; document . write ( " " ) ; printList ( head ) ; setMiddleHead ( ) ; document . write ( " " ) ; printList ( head ) ;

Accumulator variables: i
Iterator variables: i
Class/struct names: Node
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . next = this . prev = null ; } } function insert ( head_ref , data ) { new_node = new Node ( ) ; new_node . data = data ; if ( head_ref == null ) { new_node . next = new_node ; new_node . prev = new_node ; } else { last = ( head_ref ) . prev ; new_node . next = head_ref ; new_node . prev = last ; last . next = ( head_ref ) . prev = new_node ; } head_ref = new_node ; return head_ref ; } function merge ( first , second ) { if ( first == null ) return second ; if ( second == null ) return first ; if ( first . data < second . data ) { first . next = merge ( first . next , second ) ; first . next . prev = first ; first . prev = null ; return first ; } else { second . next = merge ( first , second . next ) ; second . next . prev = second ; second . prev = null ; return second ; } } function mergeUtil ( head1 , head2 ) { if ( head1 == null ) return head2 ; if ( head2 == null ) return head1 ; last_node = null ; if ( head1 . prev . data < head2 . prev . data ) last_node = head2 . prev ; else last_node = head1 . prev ; head1 . prev . next = head2 . prev . next = null ; finalHead = merge ( head1 , head2 ) ; finalHead . prev = last_node ; last_node . next = finalHead ; return finalHead ; } function printList ( head ) { temp = head ; while ( temp . next != head ) { document . write ( temp . data + " " ) ; temp = temp . next ; } document . write ( temp . data + " " ) ; } head1 = null , head2 = null ; head1 = insert ( head1 , 8 ) ; head1 = insert ( head1 , 5 ) ; head1 = insert ( head1 , 3 ) ; head1 = insert ( head1 , 1 ) ; head2 = insert ( head2 , 11 ) ; head2 = insert ( head2 , 9 ) ; head2 = insert ( head2 , 7 ) ; head2 = insert ( head2 , 2 ) ; newHead = mergeUtil ( head1 , head2 ) ; document . write ( " " ) ; printList ( newHead ) ;

Class/struct names: Node
Javascript program:
class Node { constructor ( val ) { this . data = val ; this . prev = null ; this . next = null ; } } function newNode ( val ) { var temp = new Node ( ) ; temp . data = val ; temp . prev = temp . next = null ; return temp ; } function printList ( head ) { while ( head . next != null ) { document . write ( head . data + " " ) ; head = head . next ; } document . write ( head . data ) ; } function insert ( head , val ) { var temp = newNode ( val ) ; temp . next = head ; ( head ) . prev = temp ; ( head ) = temp ; return head ; } function reverseList ( head ) { var left = head , right = head ; while ( right . next != null ) right = right . next ; while ( left != right && left . prev != right ) { var t = left . data ; left . data = right . data ; right . data = t ; left = left . next ; right = right . prev ; } return head ; } var head = newNode ( 5 ) ; head = insert ( head , 4 ) ; head = insert ( head , 3 ) ; head = insert ( head , 2 ) ; head = insert ( head , 1 ) ; printList ( head ) ; document . write ( " " ) ; head = reverseList ( head ) ; printList ( head ) ;

Class/struct names: Node
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . prev = null ; this . next = null ; } } function push ( head_ref , new_data ) { var new_node = new Node ( ) ; new_node . data = new_data ; new_node . next = head_ref ; new_node . prev = null ; if ( head_ref != null ) head_ref . prev = new_node ; head_ref = new_node ; return head_ref ; } function isPalindrome ( left ) { if ( left == null ) return true ; var right = left ; while ( right . next != null ) right = right . next ; while ( left != right ) { if ( left . data != right . data ) return false ; left = left . next ; right = right . prev ; } return true ; } var head = null ; head = push ( head , ' ' ) ; head = push ( head , ' ' ) ; head = push ( head , ' ' ) ; head = push ( head , ' ' ) ; head = push ( head , ' ' ) ; if ( isPalindrome ( head ) ) document . write ( " " ) ; else document . write ( " " ) ;

Class/struct names: Node
Javascript program:
class Node { constructor ( item ) { this . data = item ; this . left = null ; this . right = null ; } } var root = null ; function printLevels ( node , low , high ) { var Q = [ ] ; var marker = new Node ( 4 ) ; var level = 1 ; Q . push ( node ) ; Q . push ( marker ) ; while ( Q . length > 0 ) { var n = Q [ 0 ] ; Q . shift ( ) ; if ( n == marker ) { document . write ( " " ) ; level ++ ; if ( Q . length == 0 level > high ) { break ; } Q . push ( marker ) ; continue ; } if ( level >= low ) { document . write ( n . data + " " ) ; } if ( n . left != null ) { Q . push ( n . left ) ; } if ( n . right != null ) { Q . push ( n . right ) ; } } } root = new Node ( 20 ) ; root . left = new Node ( 8 ) ; root . right = new Node ( 22 ) ; root . left . left = new Node ( 4 ) ; root . left . right = new Node ( 12 ) ; root . left . right . left = new Node ( 10 ) ; root . left . right . right = new Node ( 14 ) ; document . write ( " " ) ; printLevels ( root , 2 , 3 ) ;

Accumulator variables: level
Class/struct names: Node
Javascript program:
class Node { constructor ( item ) { this . data = item ; this . left = null ; this . right = null ; } } var root = null ; function printKDistant ( node , k ) { if ( node == null k < 0 ) { return ; } if ( k == 0 ) { document . write ( node . data + " " ) ; return ; } printKDistant ( node . left , k - 1 ) ; printKDistant ( node . right , k - 1 ) ; } root = new Node ( 1 ) ; root . left = new Node ( 2 ) ; root . right = new Node ( 3 ) ; root . left . left = new Node ( 4 ) ; root . left . right = new Node ( 5 ) ; root . right . left = new Node ( 8 ) ; printKDistant ( root , 2 ) ;

Class/struct names: Node
Javascript program:
class Node { constructor ( data ) { this . left = null ; this . right = null ; this . data = data ; } } function newNode ( data ) { let newnode = new Node ( data ) ; return newnode ; } function printKDistant ( root , klevel ) { let q = [ ] ; let level = 1 ; let flag = false ; q . push ( root ) ; q . push ( null ) ; while ( q . length > 0 ) { let temp = q [ 0 ] ; if ( level == klevel && temp != null ) { flag = true ; document . write ( temp . data + " " ) ; } q . shift ( ) ; if ( temp == null ) { if ( q [ 0 ] != null ) q . push ( null ) ; level += 1 ; if ( level > klevel ) break ; } else { if ( temp . left != null ) q . push ( temp . left ) ; if ( temp . right != null ) q . push ( temp . right ) ; } } document . write ( " " ) ; return flag ; } let root = newNode ( 20 ) ; root . left = newNode ( 10 ) ; root . right = newNode ( 30 ) ; root . left . left = newNode ( 5 ) ; root . left . right = newNode ( 15 ) ; root . left . right . left = newNode ( 12 ) ; root . right . left = newNode ( 25 ) ; root . right . right = newNode ( 40 ) ; document . write ( " " ) ; let ret = printKDistant ( root , 1 ) ; if ( ret == false ) document . write ( " " + " " + " " ) ; document . write ( " " ) ; ret = printKDistant ( root , 2 ) ; if ( ret == false ) document . write ( " " + " " + " " ) ; document . write ( " " ) ; ret = printKDistant ( root , 3 ) ; if ( ret == false ) document . write ( " " + " " + " " ) ; document . write ( " " ) ; ret = printKDistant ( root , 6 ) ; if ( ret == false ) document . write ( " " + " " + " " ) ;

Accumulator variables: level
Boolean variables: flag
Class/struct names: Node
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . left = null ; this . right = null ; } } ; function printLeafNodes ( root ) { if ( root == null ) return ; if ( root . left == null && root . right == null ) { document . write ( root . data + " " ) ; return ; } if ( root . left != null ) printLeafNodes ( root . left ) ; if ( root . right != null ) printLeafNodes ( root . right ) ; } function newNode ( data ) { var temp = new Node ( ) ; temp . data = data ; temp . left = null ; temp . right = null ; return temp ; } var root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 3 ) ; root . left . left = newNode ( 4 ) ; root . right . left = newNode ( 5 ) ; root . right . right = newNode ( 8 ) ; root . right . left . left = newNode ( 6 ) ; root . right . left . right = newNode ( 7 ) ; root . right . right . left = newNode ( 9 ) ; root . right . right . right = newNode ( 10 ) ; printLeafNodes ( root ) ;

Class/struct names: Node
Javascript program:
class Node { constructor ( item ) { this . data = item ; this . left = null ; this . right = null ; } } var root = null ; function printkdistanceNodeDown ( node , k ) { if ( node == null k < 0 ) { return ; } if ( k == 0 ) { document . write ( node . data ) ; document . write ( " " ) ; return ; } printkdistanceNodeDown ( node . left , k - 1 ) ; printkdistanceNodeDown ( node . right , k - 1 ) ; } function printkdistanceNode ( node , target , k ) { if ( node == null ) { return - 1 ; } if ( node == target ) { printkdistanceNodeDown ( node , k ) ; return 0 ; } var dl = printkdistanceNode ( node . left , target , k ) ; if ( dl != - 1 ) { if ( dl + 1 == k ) { document . write ( node . data ) ; document . write ( " " ) ; } else { printkdistanceNodeDown ( node . right , k - dl - 2 ) ; } return 1 + dl ; } var dr = printkdistanceNode ( node . right , target , k ) ; if ( dr != - 1 ) { if ( dr + 1 == k ) { document . write ( node . data ) ; document . write ( " " ) ; } else { printkdistanceNodeDown ( node . left , k - dr - 2 ) ; } return 1 + dr ; } return - 1 ; } root = new Node ( 20 ) ; root . left = new Node ( 8 ) ; root . right = new Node ( 22 ) ; root . left . left = new Node ( 4 ) ; root . left . right = new Node ( 12 ) ; root . left . right . left = new Node ( 10 ) ; root . left . right . right = new Node ( 14 ) ; var target = root . left . right ; printkdistanceNode ( root , target , 2 ) ;

Class/struct names: Node