Created
March 21, 2016 09:04
-
-
Save nitsanw/258b851242d9c7fd6665 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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