title: Concatenate a queue
body: <p>I encountered this question in the book Algorithms by Sedgewick and Wayne.</p>
  
  <p>Catenable queues, stacks, or steques. Add an extra operation catenation that (destructively) concatenates two queues, stacks, or steques (see Exercise 1.3.32). Hint: Use a circular linked list, maintaining a pointer to the last item.</p>
  
  <p>The class definition for a queue looks like this.</p>
  
  <pre><code>public class Queue&lt;Item&gt; implements Iterable&lt;Item&gt; {
      private Node&lt;Item&gt; first;    // beginning of queue
      private Node&lt;Item&gt; last;     // end of queue
      private int n;               // number of elements on queue
  
      // helper linked list class
      private static class Node&lt;Item&gt; {
          private Item item;
          private Node&lt;Item&gt; next;
      }
      // methods to add and remove etc.
  }
  </code></pre>
  
  <p>The problem is how do I implement the instance method, or should I even implement one, and should I destructively update both queues? If I try to write an instance method like <code>public void catenate(Queue&lt;Item&gt; other)</code>, I can't access other's last node because it is private. If I try to write a static method <code>public static Queue&lt;Item&gt; catenante(Queue&lt;Item&gt; a, Queue&lt;Item&gt; b)</code> I encounter the same problem.</p>