package com.company;
import javax.swing.tree.TreeNode;
import java.lang.reflect.Array;
import java.util.*;
public class Main {
public static void main(String[] args) {
ListNode head = new ListNode();
head.val = 2;
ListNode second=new ListNode();
second.val=3;
head.next = second;
ListNode third=new ListNode();
third.val=4;
head.next.next=third;
ListNode list = reverseList(head);
}
public static ListNode reverseList(ListNode head) {
ListNode pre=null;
ListNode cur=head;
while(cur!=null){
ListNode tmp=cur.next;//对原链表进行移动
cur.next=pre;//改变方向----新链表
pre=cur;//对原链表进行移动
cur=tmp;//对原链表进行移动
}
return pre;
}
static class ListNode {
private int val;
private ListNode next;
}
}