一道关于单链表反转的java代码补全题

请问对于下面的代码,怎样能只在while补全代码,就能使该函数达到单链表反转的效果!请大家帮帮忙!

class Node {
    int data;
    Node next;
}

public Node reverse(Node head) {  
    Node newhead = null;
    Node current = head;
    while (current != null) {

    }
    return newhead; 
}
阅读 3.2k
1 个回答
Node next = current.next;
current.next = newhead;
newhead = current;
current = next;
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题