单链表反转(非递归java实现)

java代码:

class NodeList{
    public int value;
    public NodeList next;
    public NodeList(int data){
        this.value = data;
        }
}
NodeList reverseNodelist(Node head){
        NodeList pre = null;
        NodeList nextNode = null;
        while(head!=null){
                nextNode = head.next;
                head.next = pre;
                pre = head;
                head = nextNode;    
        }
        return pre;
}

你可能感兴趣的:(单链表反转(非递归java实现))