Q. Program to convert a given binary tree to doubly linked list.ExplanationIn this program, we need to convert the given binary tree to corresponding doubly liked list. The binary tree is a tree data structure in which each node has at most two children node. This can be achieved by traversing the tree in the in-order manner that is, left the child -> root ->right node. Traverse left sub-tree and convert it into the doubly linked list by adding nodes to the end of the list. In this way, leftmost node will become head of the list. Then, convert the right sub-tree into the doubly linked list. Binary tree: Corresponding doubly linked list: Algorithm
SolutionPythonOutput: Nodes of generated doubly linked list: 4 2 5 1 6 3 7 COutput: Nodes of generated doubly linked list: 4 2 5 1 6 3 7 JAVAOutput: Nodes of generated doubly linked list: 4 2 5 1 6 3 7 C#Output: Nodes of generated doubly linked list: 4 2 5 1 6 3 7 PHPOutput: Nodes of generated doubly linked list: 4 2 5 1 6 3 7 Next Topic# |