title: Nodes, Queues, De-queues
body: <p>I'm doing this small project of creating a queue and a de-queue in the same class along with using my own Node class and an interface.</p>
  
  <p>The problem i'm facing is I've done all methods but can't get the method removeLast to work because i'm unable to let rear link to the node before it, after getting removed. Please help me with your suggestions? Thank you.</p>
  
  <p>My node class.</p>
  
  <pre><code>public class Node&lt;T&gt; {
  
    T info;
    Node&lt;T&gt; next;
  
    public Node(T element) {
      info = element;
      next = null;
    }
  
    public void setInfo(T element) {
      info = element;
    }
  
    public T getInfo() {
      return info;
    }
  
    public void setNext(Node&lt;T&gt; next) {
      this.next = next;
    }
  
    public Node&lt;T&gt; getNext() {
      return next;
    }
  
  }
  </code></pre>
  
  <p>My interface class</p>
  
  <pre><code>public interface DequeInterface&lt;T&gt; {
  
    void addFront(T element);
  
    void addLast(T element);
  
    T removeFront();
  
    T removeLast();
  
    boolean isEmpty();
  
    int getSize();
  }
  </code></pre>
  
  <p>My deque class</p>
  
  <pre><code>import java.util.NoSuchElementException;
  
  public class Deqeue&lt;T&gt; implements DequeInterface {
  
    public Node&lt;T&gt; front;
    public Node&lt;T&gt; rear;
    int size;
  
    public Deqeue() {
      front = null;
      rear = null;
      size = 0;
    }
  
    @Override
    public T removeFront() {
      if (isEmpty()) {
        throw new NoSuchElementException();
      }
      T element = front.getInfo();
      front = front.getNext();
      size--;
      return element;
    }
  
    @Override
    public T removeLast() {
      if (isEmpty()) {
        throw new NoSuchElementException();
      }
      T element = rear.getInfo();
      size--;
      return element;
    }
  
    @Override
    public int getSize() {
      return size;
    }
  
    @Override
    public boolean isEmpty() {
      return rear == null;
    }
  
    @Override
    public void addFront(Object element) {
      Node&lt;T&gt; newNode = front;
  
      if (newNode == null) {
        rear = front;
      }
        front = new Node(element);
        front.setNext(newNode);
        size++;
    }
  
    @Override
    public void addLast(Object element) {
      Node&lt;T&gt; newNode = rear;
  
      if (newNode == null) {
        front = rear;
      }
        rear = new Node(element);
        newNode.setNext(rear);
        size++;
  
      }
    }
  </code></pre>