zoukankan      html  css  js  c++  java
  • 链表

    链表(可以看看你之前的笔记,线性表或顺序表,即使总结,每次学完花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不让它警告。

    成年人的世界没有那么多的童话,也没有那么多的逆袭。
  • 相关阅读:
    服务器Nginx 反向代理 其他服务器 8181端口 失败的问题
    Nginx 文件下载 apk 文件下载不了
    https和http 调用过程中请求头 referrer 获取不到的问题
    windows 下 nginx log 分割
    使用Windows Service Wrapper快速创建一个Windows Service 如nginx
    VS 中 无法嵌入互操作类型“……”,请改用适用的接口的解决方法
    使用With递归查询 树
    nginx 常用命令
    (译)(function (window, document, undefined) {})(window, document); 真正的意思
    在Emacs 24.4中使用在线字典
  • 原文地址:https://www.cnblogs.com/shijinglu2018/p/8322141.html
Copyright © 2011-2022 走看看