有一个带头结点的单链表L,设计算法将L逆置

2024-11-05 02:12:15
推荐回答(1个)
回答1:

LinkNode last = null;
while(L.hasNext()) {
node = L.next();
Node newnode = node.clone();
newnode.setNext(last);
last = newnode;
}

return last; //last是逆置的链表的头结点