title: Sorting Queue in Java with recursion
body: <p>I am trying to sort a queue (in ascending order), using the recursion method. The input is entered by the user.
  This one below is not giving me the correct output.  For instance: 12. Elements: 6 12 3 4 5 1 7 8 10 9 11 2, result: 2 11 9 10 8 7 1 5 4 3 12 6, which is incorrect. I am trying to figure out which part is not correct. I do not want to change anything in the main method.</p>
  <pre><code>import java.util.*;
  
  public class Source {
      public static void main(String args[]) {
          Queue&lt;Integer&gt; queue = new LinkedList&lt;Integer&gt;();
          Scanner s = new Scanner(System.in);
          int n = s.nextInt();
          while (n-- &gt; 0) 
              queue.add(s.nextInt());
          sort(queue);
      }
      
      static void FrontToLast(Queue&lt;Integer&gt; queue,int qsize) {
   
      if (qsize &lt;= 0) {
          return; 
      }
      queue.add(queue.peek()); 
      queue.remove(); 
      FrontToLast(queue, qsize - 1); 
      }
    
  
      static void pushInQueue(Queue&lt;Integer&gt; queue , int temp, int qsize) {
      if (queue.isEmpty() || qsize == 0)  
      { 
          queue.add(temp); 
          return; 
      }
      else if (temp &lt;= queue.peek()) 
      { 
          queue.add(temp);
          FrontToLast(queue, qsize); 
      }
      else 
      { 
          queue.add(queue.peek()); 
          queue.remove(); 
          pushInQueue(queue, temp, qsize - 1); 
      }
  }
      static void sort(Queue&lt;Integer&gt; queue) {
          if (queue.isEmpty()) {
          return; 
          }
          int temp = queue.peek();
           queue.remove(); 
           sort(queue); 
           pushInQueue(queue, temp, queue.size());
            
          while (!queue.isEmpty())  
      { 
          System.out.print(queue.peek() + &quot; &quot;); 
          queue.remove();
      }
      }
  }
  
  
      
  </code></pre>