private static btol treetodllHelper(BNode root) { if (root == null) { return(new btol(null, null)); } btol l = treetodllHelper(root.left); btol r = treetodllHelper(root.right); root.left = l.tail; if (l.tail != null) { l.tail.right = root; } else { l.head = root; } root.right = r.head; if (r.head != null) { r.head.left = root; } else { r.tail = root; } return(new btol(l.head, r.tail)); }
private static void binaryTreetodll() { BNode root = new BNode(); root.data = 5; BNode a = new BNode(); a.data = 4; BNode b = new BNode(); b.data = 8; BNode c = new BNode(); c.data = 11; BNode d = new BNode(); d.data = 13; BNode e = new BNode(); e.data = 4; BNode f = new BNode(); f.data = 7; BNode g = new BNode(); g.data = 2; BNode h = new BNode(); h.data = 5; BNode i = new BNode(); i.data = 1; root.left = a; root.right = b; a.left = c; b.left = d; b.right = e; c.left = f; c.right = g; e.left = h; e.right = i; TreePrinter.Print(root); btol bto = treetodllHelper(root); var cur = bto.head; while (cur != null) { Console.WriteLine(cur.data); cur = cur.right; } //TreePrinter.Print(bto.head); }