title: FIFO queue with one pointer
body: <p>So hello everybody , I wrote a fifo queue implementation in java with 2 pointers (head,tail). I would like to know if is there any way to create a fifo circular queue that uses only the head pointer.Any suggestion is appreciated.</p>
  
  <p>My code is the following :</p>
  
  <pre><code>import java.io.PrintStream;
  import java.util.*
  
  public class StringQueueImpl&lt;T&gt; implements StringQueue {
  
  private int total;         // number of elements on queue
  private Node head;    // beginning of queue
  private Node tail;     // end of queue
  
  private class Node {
      T ele;
      Node next;
      Node(T ele) {
      this.ele = ele;
      next = null; } 
  } 
   /**
   * Creates an empty queue.
   */
  public StringQueueImpl() {
      first = null;
      last  = null;
      total = 0;
  }
  
  boolean isEmpty() {
      return (head == null); 
  }
  
  public &lt;T&gt; void put(T ele) {
      Node t = tail;
      tail = new Node(ele);
      if (isEmpty()) head = tail;
      else t.next = tail; 
      total++;
  } 
  
  public T get() {
      if (isEmpty()) throw new NoSuchElementException();
      T v = head.ele;
      Node t = head.next;
      head = t;
      return v; 
      total--;
  } 
  
  
  public T peek() {
      if (isEmpty()) throw new NoSuchElementException();
      return head.ele;
  }
  
  Node node = head; 
  public void printQueue(PrintStream stream){
      while(node != null){
          stream.println(node.ele);
          stream.flush();
          node = node.next;
      }
  }
  
  public int size(){
      return total;
  }
  
  }
  </code></pre>