/**
* 题目描述:
* 输入一个链表,反转链表后,输出新链表的表头。
* @author syf
*
*/
public class 反转链表 {
/**
* 思路:
* 链表反转,head->pre->next1->next2,反转之后pre<-head,考虑到断链的情况
* @param head
* @return
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Node resever(Node head){
if(head == null ){
return null;
}
Node pre = null ;
Node next = null ;
while(head != null){
next = head.next ;
head.next = pre ;
pre = head ;
head = next ;
}
return null;
}
}
class Node<T>{
T data ;
@SuppressWarnings("rawtypes")
Node next ;
public Node(T data){
this.data = data ;
}
}