Implementing queue in java

后端 未结 3 2018
攒了一身酷
攒了一身酷 2021-01-29 14:16

Implementing a queue in Java is pretty common interview question. I surfed online and saw many implementations where they do fancy stuff like implementing queue interface and wr

3条回答
  •  时光说笑
    2021-01-29 14:22

    public class Queue{
    private LinkedList list=new LinkedList<>();
    
    public void insert(T element){
         list.addLast(element);
    }
    
    public void remove(){
        list.removeFirst();
    }
    
    public int size(){
        return list.size();
    }
    
    public T element(){
         return list.getFirst();
    }
    }
    

提交回复
热议问题