我写了一个创建链表副本的方法。
你们能想出比这更好的方法吗?
public static Node Duplicate(Node n)
{
Stack<Node> s = new Stack<Node>();
while (n != null)
{
Node n2 = new Node();
n2.Data = n.Data;
s.Push(n2);
n = n.Next;
}
Node temp = null;
while (s.Count > 0)
{
Node n3 = s.Pop();
n3.Next = temp;
temp = n3;
}
return temp;
}