Reverse a singly linked list.
用三个指针 tail
,p
,q
,紧紧相邻,不断前进,每次将p.next
指向tail
,将q.next
指向p
。
{% if book.java %} {% codesnippet "./code/reverse-linked-list-1."+book.suffix, language=book.suffix %}{% endcodesnippet %} {% endif %}
{% if book.java %} {% codesnippet "./code/reverse-linked-list-2."+book.suffix, language=book.suffix %}{% endcodesnippet %} {% endif %}