其他分享
首页 > 其他分享> > 一个队列存放几千万上亿的数据,应该如何设计这个队列?只需要在头尾进行添加、删除

一个队列存放几千万上亿的数据,应该如何设计这个队列?只需要在头尾进行添加、删除

作者:互联网

class Node<V>{
     V value;
     Node<V> next;
     Node<V> last;
     public Node(V value){
        this.value = value;
     }
}

public class DoubleLinkedList<V>{
     Node<V> head;
     Node<V> tail;
     public DoubleLinkedList(){
         this.head = null;
         this.tail = null;
     }
     public void addHead(Node<V> node){
        if(this.head == null){
             this.head = node;
             this.tail = node;
        }else{
            node.next = this.head;
            this.head = node;
        }
    }
    public Node<V> removeHead(){
         if(this.head == null){
            return null;
         }else if(this.head.next == null){
             Node<V> tmp = this.head;
             this.head = null;
             this.tail = null;
             return tmp;
         }else{
             Node<V> tmp = this.head;
             this.head = this.head.next;
             return tmp;
         } 
    }
}

用双向链队列

 

标签:头尾,Node,head,node,队列,几千万,next,null,public
来源: https://blog.csdn.net/shen19960603/article/details/99671850