数据结构 -- 链表

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值