Convert a given Binary Tree to Circular Doubly Linked List | Set 2 | Java program for conversion of Binary Tree to CDLL ; 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
import java . util . * ; class GFG { static class Node { int data ; Node left ; Node right ; Node ( int x ) { data = x ; left = right = null ; } } ; static void inorder ( Node root , Vector < Integer > v ) { if ( root == null ) return ; inorder ( root . left , v ) ; v . add ( root . data ) ; inorder ( root . right , v ) ; } static Node bTreeToCList ( Node root ) { if ( root == null ) return null ; Vector < Integer > v = new Vector < > ( ) ; inorder ( root , v ) ; Node head_ref = new Node ( v . get ( 0 ) ) ; Node curr = head_ref ; for ( int i = 1 ; i < v . size ( ) ; i ++ ) { Node temp = curr ; curr . right = new Node ( v . get ( i ) ) ; curr = curr . right ; curr . left = temp ; } curr . right = head_ref ; head_ref . left = curr ; return head_ref ; } static void displayCList ( Node head ) { System . out . println ( " Circular ▁ Doubly ▁ Linked ▁ List ▁ is ▁ : " ) ; Node itr = head ; do { System . out . print ( itr . data + " ▁ " ) ; itr = itr . right ; } while ( head != itr ) ; System . out . println ( ) ; } public static void main ( String [ ] args ) { Node 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 ) ; Node head = bTreeToCList ( root ) ; displayCList ( head ) ; } }