zoukankan      html  css  js  c++  java
  • 数据结构-单向链表

    Node类

    //链表结构
    public class Node {
        //数据
        public long data;
        //指针,连接下个结点
        public Node next;
    
        public Node(long value){
            this.data=value;
        }
    
        public void display(){
            System.out.print(data+" ");
        }
    }
    
    

    链表的常用方法

    public class LinkList {
        //头结点
        private Node first;
    
        //构造方法
        public LinkList(){
            first=null;
        }
    
        //每次添加都添加在开头
        public void insertFirst(long value){
            Node node = new Node(value);
            node.next=first;
            first=node;
    
    
        }
    
        //删除头结点
        public Node deleteFirst(){
            Node temp = first;
            first=temp.next;
            return temp;
    
        }
    
        //遍历
        public void display(){
            Node cur = first;
            while (cur!=null){
                cur.display();
                cur=cur.next;
            }
            System.out.println();
        }
    
        //根据值查找结点
        public Node find(long value){
            Node cur = first;
            while (cur.data!=value){
                if (cur.next==null){
                    return null;
                }
                cur=cur.next;
            }
            return cur;
        }
    
        //删除指定值
        public Node delete(long value){
            Node cur = first;
            Node pre = first;
            while (cur.data!=value){
                if (cur.next==null){
                    return null;
                }
                pre = cur;
                cur = cur.next;
    
            }
            if (cur==first){
                first=first.next;
            }
            pre.next = cur.next;
            return cur;
        }
    }
    
    
  • 相关阅读:
    Callable的Future模式
    并发队列
    并发工具类和线程池
    安全与死锁问题
    ConcurrentHashMap底层实现
    Map集合常见面试题
    List集合框架
    类加载器
    Activiti中个人任务分配
    流程定义
  • 原文地址:https://www.cnblogs.com/hellosiyu/p/12465988.html
Copyright © 2011-2022 走看看