using System.Collections.Generic;
public static void Main()
ListFromTree2 obj = new ListFromTree2();
public class ListFromTree2
public static Node generalNode = new Node();
public Node prevNode = generalNode;
Node tree = createTree();
KeyValuePair<Node, Node> result = FlatTree(tree, null);
public KeyValuePair<Node,Node> FlatTree(Node node, Node parent) {
if (node.Left == null && node.Right == null) {
return new KeyValuePair<Node,Node>(node, node);
KeyValuePair<Node, Node> leftNode = FlatTree(node.Left, node);
KeyValuePair<Node, Node> rightNode = FlatTree(node.Right, node);
leftNode.Value.Right = node;
node.Right = rightNode.Key;
KeyValuePair<Node, Node> result = new KeyValuePair<Node, Node>(leftNode.Key, rightNode.Value);
public Node createTree() {