class Node
{
public object data;
public Node next;
public Node(object data)
{
this.data = data;
}
}
/// <summary>
/// 带头结点的单链表倒置
/// </summary>
public static void reverseSimpleNodesWithHead(Node head)
{
Node p = head.next;
Node q = null;
while (p.next != null)
{
q = p.next;
p.next = q.next;
q.next = head.next;
head.next = q;
}
}
/// <summary>
/// 不带头结点的单链表倒置
/// </summary>
public static Node reverseSimpleNodes(Node node)
{
Node p = node;
Node q = null;
Node cur = node;
while (p.next != null)
{
q = p.next;
p.next = q.next;
q.next = cur;
cur = q;
}
return cur;
}