title: reversing a queue in a non-conventional way
body: <p>Suppose I have a queue filled with some type of elements, and they are filled in such a way that if any two elements are the assessed as the same by a designated comparer, they will be adjacent to each other.</p>
  
  <p>Now I want to reverse the queue in the following way: If all elements in the queue are unique, then reverse it as the normal definition of reverse.</p>
  
  <p>If there are some elements that are the same (and they will be adjacent to each other given how they are filled in), reverse the queue but keep the relative position of the non-unique elements intact.</p>
  
  <p>A diagram might be easier to understand what the problem is.</p>
  
  <p>If a queue is as the following:</p>
  
  <pre><code>[11 22 33 44 55]
  </code></pre>
  
  <p>and my comparer compares two integers by looking at their first digit, then the reverse of the queue above would be:</p>
  
  <pre><code>[55 44 33 22 11]
  </code></pre>
  
  <p>However, if my input queue is:</p>
  
  <pre><code>[11 22 23 44 55]
  </code></pre>
  
  <p>the reverse should be:</p>
  
  <pre><code>[55 44 22 23 11]
  </code></pre>
  
  <p>given the comparer.</p>
  
  <p>I am trying to do this in a recursive way with only one stack as an additional auxiliary storage. However, I am having difficulty figuring out a correct and effective way. Could you please help? Thank you very much!</p>
  
  <p>PS: The reason I am using a stack as extra storage is because reversing a queue in the conventional way is done most easily with a stack (dequeue and push all into stack, then pop and enqueue back into the queue).</p>