Guest User

Untitled

a guest
Oct 22nd, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. public class NodeQueue<E> implements QueueADT<E> {
  2.  
  3. protected Node<E> head;
  4. protected Node<E> tail;
  5. protected int size;
  6.  
  7. public NodeQueue(){
  8. head=null;
  9. tail=null;
  10. size=0;
  11. }
  12.  
  13. public void enqueue(E element) {
  14. Node<E> v = new Node<E>(element,tail);
  15. tail = v;
  16. size++;
  17. }
  18.  
  19.  
  20. public E dequeue() {
  21. if (isEmpty()) throw new
  22. EmptyQueueException("The Queue is empty. Cannot dequeue from Queue.");
  23. E deq = head.getElement();
  24. head = head.getNext();
  25. size--;
  26. return deq;
  27. }
  28.  
  29.  
  30. public E front() {
  31. if (isEmpty()) throw new
  32. EmptyQueueException ("The Queue is empty. Can't show the front element.");
  33. return head.getElement();
  34. }
  35.  
  36.  
  37. public int size() {
  38. return size;
  39. }
  40.  
  41.  
  42. public boolean isEmpty() {
  43. return head==null;
  44. }
  45.  
  46. }
Add Comment
Please, Sign In to add comment