链表

链表(可以看看你之前的笔记,线性表或顺序表,即使总结,每次学完花10分钟左右的时间总结一下)
public class Node{
    //数据域
    public long data;
    //节点域或者指针域,引用类型为Node类,引用类型
    public Node next;

    //创建构造方法
    public Node(long value){
        this.data=value;
    }
    /*显示方法
    */
    public void display(){
        System.out.println(data+"");
    }
}

/*链表相当于它的火车*/
public class LinkList{
    //头节点
    private Node first;

    public LinkList(){
        first=null;
    }

    /*插入一个节点,在头结点后插入,理解得不够透彻??再理解一下
    */
    public void insertFirst(long value){
        //创建新节点把value传进去
        Node node=new Node(value);
        //添加的新节点的指针域指向
        node.next=first;
        //下面这一行代码怎么理解??再理解一下
        first=node;
        
        
        //我记得赋值是自右向左的,但这好像是反的


    }

    /*删除节点*/
    public Node deleteFirst(){
        Node tmp=first;
        first=tmp.next;
        return tmp;
    }

    /*显示方法*/
    public void display(){
        Node current=first;
        //first头结点?
        while(current !=null){
            current.display();
            current=current.next();

        }
        System.out.println();
    }

    /*查找方法*/
    public Node find(long value){
        Node current=first;
        while(current.data!=value){
            if (current.next==null) {
                return null;
            }
            return current;
        }
    }
    /*删除方法,根据数据域来进行删除*/
    public Node delete(long value){
        Node current=first;
        Node previous=first;
        while(current.data!=value){
            if (current.next==null) {
                return null;
            }
            previous=current;
            current=current.next;
        }
        if (current==first) {
            first=first.next;

        }else{
            privious.next=current.next;
        }
        return current;
    }
}

public class TestLinkList{
    public static void main(String[] args) {
        LinkList linkList=new LinkList();
        linkList.insertFirst(34);
        linkList.insertFirst(23);
        linkList.insertFirst(12);
        linkList.insertFirst(0);
        linkList.insertFirst(-1);

        /*linkList.display();
        linkList.deleteFirst();
        linkList.display();

        Node node=linkList.find(23);
        //为什么要加“Node node=”?
        node.display();*/

        Node node1=linkList.delete(0);
        //删除元素
        node1.display();
        //显示被删除的元素
        linkList.display();




    }
}

 

JDK中有关标注

2.@Deprecated

这是标注已过时的成员的标注类型。

表示某些方法已经过时了,建议不要再使用了。

3.@SuppressWarnings

编译器有时警告某些方法、变量、类时,SuppressWarnings不让它警告。

成年人的世界没有那么多的童话,也没有那么多的逆袭。
原文地址:https://www.cnblogs.com/shijinglu2018/p/8322141.html