自从我早已没有使用C或C++,所以完全忘记了Pointers。我熟悉C#并且已经写了一个基本版本。需要知道我是否正确/错误?在单个链表上交换节点
输入:链表A-> B-> C-> D-> E->空
输出:链表B-> A-> D-> C-> E->空
我们必须编写代码,以便交换内存位置,而不是节点值。
public void SwapLinkedList(LinkedList<int> LL)
{
LinkedListNode<int> current = LL.First;
while (current.Next != null)
{
int temp = current.Next.Value;
current.Next.Value = current.Value;
current.Value = temp;
current = current.Next.Next;
}
}
定义“交换”。这段代码将第一个列表值正确地放在最后,它是你想要它做什么的? – 2010-08-13 04:00:39
看看这个帖子 http://stackoverflow.com/questions/1535988/swapping-nodes-on-a-single-linked-list – Alam 2010-08-13 04:07:54