Today to the inter-chain interview, the results in coding this one off and folded.
Well, then, let's just wrap it up and rip the code off.
First define a ListNode:
Public class ListNode { int data; ListNode Next; public ListNode (int data, ListNode next) { this. Data= data; this. Next = next;} }
Define the method:
Public classListnodereverse { Public Static voidMain (string[] args) {ListNode D=NewListNode (4,NULL); ListNode C=NewListNode (3, D); ListNode B=NewListNode (2, C); ListNode A=NewListNode (1, B); ListNode node=reverse (A); System.out.println ("NULL"); } Public StaticListNode Reverse (listnode listnode) {//the idea of iterationListNode pre =NULL; ListNode Now=ListNode; while(Now! =NULL) {ListNode next=Now.next; Now.next=Pre; Pre=Now ; now=Next; } returnPre; }}
Execution Result:
One-way linked list inversion There are other efficient methods, welcome to Exchange Learning!!!!!
Reverse single-linked list of hand RIP codes