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 : NEW_LINE INDENT def __init__ ( self , data ) : NEW_LINE INDENT self . data = data NEW_LINE self . left = self . right = None NEW_LINE DEDENT DEDENT v = [ ] NEW_LINE def inorder ( root ) : NEW_LINE INDENT global v NEW_LINE if ( root == None ) : NEW_LINE INDENT return NEW_LINE DEDENT inorder ( root . left ) NEW_LINE v . append ( root . data ) NEW_LINE inorder ( root . right ) NEW_LINE DEDENT def bTreeToCList ( root ) : NEW_LINE INDENT global v NEW_LINE if ( root == None ) : NEW_LINE INDENT return None NEW_LINE DEDENT v = [ ] NEW_LINE inorder ( root ) NEW_LINE head_ref = Node ( v [ 0 ] ) NEW_LINE curr = head_ref NEW_LINE i = 1 NEW_LINE while ( i < len ( v ) ) : NEW_LINE INDENT temp = curr NEW_LINE curr . right = Node ( v [ i ] ) NEW_LINE curr = curr . right NEW_LINE curr . left = temp NEW_LINE i = i + 1 NEW_LINE DEDENT curr . right = head_ref NEW_LINE head_ref . left = curr NEW_LINE return head_ref NEW_LINE DEDENT def displayCList ( head ) : NEW_LINE INDENT print ( " Circular ▁ Doubly ▁ Linked ▁ List ▁ is ▁ : " , end = " " ) NEW_LINE itr = head NEW_LINE while ( True ) : NEW_LINE INDENT print ( itr . data , end = " ▁ " ) NEW_LINE itr = itr . right NEW_LINE if ( head == itr ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT print ( ) NEW_LINE DEDENT root = Node ( 10 ) NEW_LINE root . left = Node ( 12 ) NEW_LINE root . right = Node ( 15 ) NEW_LINE root . left . left = Node ( 25 ) NEW_LINE root . left . right = Node ( 30 ) NEW_LINE root . right . left = Node ( 36 ) NEW_LINE head = bTreeToCList ( root ) NEW_LINE displayCList ( head ) NEW_LINE