【发布时间】:2014-12-28 15:33:07
【问题描述】:
我正在尝试将二叉树转换为 C# 中的双链表。
DLL中节点的顺序必须是二叉树的中序遍历。
代码如下:
public void BSTtoDLL(ref Node root,ref Node head,ref Node tail)
{
if (root == null) return;
BSTtoDLL(ref root.left,ref head,ref tail);
if (tail != null)
{
root.left = tail;
tail.right = root;
}
else
{
head = root;
}
tail = root;
BSTtoDLL(ref root.right,ref head, ref tail);
}
但我得到堆栈溢出异常?
我错过了什么?
【问题讨论】:
标签: c# .net data-structures