Convert a given Binary Tree to Circular Doubly Linked List | Set 2 | A binary tree node has data , and left and right pointers ; Function to perform In - Order traversal of the tree and store the nodes in a vector ; first recur on left child ; append the data of node in vector ; now recur on right child ; Function to convert Binary Tree to Circular Doubly Linked list using the vector which stores In - Order traversal of the Binary Tree ; Base cases ; Vector to be used for storing the nodes of tree in In - order form ; Calling the In - Order traversal function ; Create the head of the linked list pointing to the root of the tree ; Create a current pointer to be used in traversal ; Traversing the nodes of the tree starting from the second elements ; Create a temporary pointer pointing to current ; Current 's right points to the current  node in traversal ; Current points to its right ; Current 's left points to temp ; Current 's right points to head of the list ; Head 's left points to current ; Return head of the list ; Display Circular Link List ; Driver Code
class Node { constructor ( val ) { this . data = val ; this . left = null ; this . right = null ; } } function inorder ( root , v ) { if ( root == null ) return ; inorder ( root . left , v ) ; v . push ( root . data ) ; inorder ( root . right , v ) ; } function bTreeToCList ( root ) { if ( root == null ) return null ; var v = [ ] ; inorder ( root , v ) ; var head_ref = new Node ( v [ 0 ] ) ; var curr = head_ref ; for ( i = 1 ; i < v . length ; i ++ ) { var temp = curr ; curr . right = new Node ( v [ i ] ) ; curr = curr . right ; curr . left = temp ; } curr . right = head_ref ; head_ref . left = curr ; return head_ref ; } function displayCList ( head ) { document . write ( " " ) ; var itr = head ; do { document . write ( itr . data + " " ) ; itr = itr . right ; } while ( head != itr ) ; document . write ( ) ; } var root = new Node ( 10 ) ; root . left = new Node ( 12 ) ; root . right = new Node ( 15 ) ; root . left . left = new Node ( 25 ) ; root . left . right = new Node ( 30 ) ; root . right . left = new Node ( 36 ) ; var head = bTreeToCList ( root ) ; displayCList ( head ) ;