We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
如何实现链表的逆序。
The text was updated successfully, but these errors were encountered:
function Node(value){//创建节点类 this.value = value; this.node = null } //创建五个链表节点 var node1 = new Node(1); var node2 = new Node(2); var node3 = new Node(3); var node4 = new Node(4); var node5 = new Node(5); //将五个节点连接起来 node1.next = node2; node2.next = node3; node3.next = node4; node4.next = node5; //通过递归方式,将链表顺序逆转 function reserveList(root){ //下面的if条件是递归的结束条件 if(root.next.next == null){//判断是否是倒数第二个节点 root.next.next = root;//将最后一个节点的next指向倒数第二个节点 return ; }else{//不是倒数第二个节点 reserveList(root.next);//继续递归 root.next.next = root ;//将下一个节点的next指向当前节点 root.next = null;//将当前节点的next指向null } }
Sorry, something went wrong.
No branches or pull requests
如何实现链表的逆序。
The text was updated successfully, but these errors were encountered: