How to realize reverse output linked list by Java
This article mainly introduces "Java how to achieve reverse output linked list". In daily operation, I believe that many people have doubts about how to achieve reverse output linked list in Java. Xiaobian consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubt of "how to achieve reverse output linked list in Java". Next, please follow the editor to study!
The code: # include # include//copy using namespace std;const int naught2struct node {int iscape node * next;}; node * Reverse (node * head) {/ / determine whether the linked list is empty assert (head! = NULL & & "function Reverse: list is null!"); node * temp=head- > next;// linked list has only one element if (temp= = NULL) return head;// linked list head-- > temp-- > tail before flipping, tail-- > temp-- > headhead- > next=NULL Node * tail=temp- > next;while (tail! = NULL) {temp- > next=head;head=temp;temp=tail;tail=tail- > next;} temp- > next=head;// returns the flipped chain header pointer return temp;} void Print (node * head) {while (head! = NULL) {coutnext=temp;tail=temp;} Print (head); cout