Skip to content

Instantly share code, notes, and snippets.

@nitsanw
Created March 21, 2016 09:04
Show Gist options
  • Save nitsanw/258b851242d9c7fd6665 to your computer and use it in GitHub Desktop.
Save nitsanw/258b851242d9c7fd6665 to your computer and use it in GitHub Desktop.
public class SampleLinkedQueue<E> {
static class Node<E> {
Node next;
E value;
}
Node<E> head;
Node<E> tail;
SampleLinkedQueue(){
head = tail = new Node<E>();
}
void offer(E e) {
head = head.next = new Node<E>();
head.value = e;
}
E poll() {
if (tail.next == null) return null;
tail = tail.next;
E e = tail.value;
tail.value = null;
return e;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment