📜  stackoverflow 反向链表 - 任何代码示例

📅  最后修改于: 2022-03-11 14:59:38.287000             🧑  作者: Mango

代码示例1
public Node getLastNode()
{
    if(next != null)
        return next.getLastNode();
    else
        return this;
}

public Node reverse(Node source)
{
    Node reversed = source.getLastNode();
    Node cursor = source;

    while(cursor != reversed)
    {
        reversed.addNodeAfter(cursor.getInfo());
        cursor = cursor.getNodeAfter();
    }

    source = reversed;
    return source;
}