数据结构 -- 链表

1. 链表 -- 增

2. 链表 -- 删

3. 链表 -- 遍历

4. 链表 -- 反向遍历

5. 链表 -- 反转链表

DEMO : 

package lime.xiaoniu;

/**
 * Created by LimeOracle on 2017/11/17.
 */
public class DevilList {
    public static void main(String[] args){
        DevilList list = null;
        for(int i = 1;i < 11;i++){
            list = DevilList.addList(list, i);
        }
        for(int i = 10;i > 0;i--) {
            list = deleteList(list, i);
            DevilList.inOrder(list);
            System.out.println();
        }
    }
    private Integer data;
    private DevilList next;

    public DevilList(Integer data) {
        this.data = data;
    }
    //添加
    public static DevilList addList(DevilList head , Integer data){
        if(null == head){
            return new DevilList(data);
        }
        head.next = addList(head.next,data);
        return head;
    }
    //遍历
    public static void inOrder(DevilList head){
        if(null == head){
            return;
        }
        System.out.print(head.data + "  ");
        inOrder(head.next);
    }
    //反向遍历
    public static void reversalData(DevilList head){
        if(null == head){
            return;
        }
        reversalData(head.next);
        System.out.print(head.data + "  ");
    }
    //反转
    public static DevilList reversalList(DevilList head){
        if(null == head || null == head.next){
            return head;
        }
        DevilList reversalHead = reversalList(head.next);
        head.next.next = head;
        head.next = null;
        return reversalHead;
    }
    //删除
    public static DevilList deleteList(DevilList head,int data){
        if(null == head){
            return head;
        }
        if(data == head.data){
            head = head.next;
        }else{
            head.next = deleteList(head.next,data);
        }
        return head;
    }



    @Override
    public String toString() {
        return "ReversalList{" +
                "data=" + data +
                ", next=" + next +
                '}';
    }
}

啦啦啦

原文地址:https://www.cnblogs.com/ClassNotFoundException/p/7865197.html