Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class NodeQueue<E> implements QueueADT<E> {
- protected Node<E> head;
- protected Node<E> tail;
- protected int size;
- public NodeQueue(){
- head=null;
- tail=null;
- size=0;
- }
- public void enqueue(E element) {
- Node<E> v = new Node<E>(element,tail);
- tail = v;
- size++;
- }
- public E dequeue() {
- if (isEmpty()) throw new
- EmptyQueueException("The Queue is empty. Cannot dequeue from Queue.");
- E deq = head.getElement();
- head = head.getNext();
- size--;
- return deq;
- }
- public E front() {
- if (isEmpty()) throw new
- EmptyQueueException ("The Queue is empty. Can't show the front element.");
- return head.getElement();
- }
- public int size() {
- return size;
- }
- public boolean isEmpty() {
- return head==null;
- }
- }
Add Comment
Please, Sign In to add comment