A Fifo queue with fast insertion , deletion and get front element java -


which data structure should use in java implement queue fast insertion @ end , deletion front , , operation first element?

wouldn't linkedlist fit bill?

its implementation

public e remove() {     return removefirst(); }  public boolean add(e e) {     linklast(e);     return true; } 

it has both first , last nodes, insertion fast @ end. can delete front method remove(). can first element well, ie. peek() returns first node. that's o(1).

source

void linklast(e e) {     final node<e> l = last;     final node<e> newnode = new node<>(l, e, null);     last = newnode;     if (l == null)         first = newnode;     else         l.next = newnode;     size++;     modcount++; } 

Comments

Popular posts from this blog

Line ending issue with Mercurial or Visual Studio -

tags - Jquery Mixitup plugin help prevent handlers being destroyed -

c# - Delving into the world of XML (Windows Phone) Error I dont understand (The ' ' character, hexadecimal value 0x20, cannot be included in a name.) -