title: Implement a priority queue using stack
body: <p>My idea is to add data into an ArrayList, sort it and then return the data to the Stack. It sounds circuitous but do you guys have better implementation?</p>
  
  <pre><code>class MyPriorityQueue {
    private Stack&lt;Integer&gt; st;
    private ArrayList&lt;Integer&gt; list;
  
    public MyPriorityQueue() { // The constructor
      st = new Stack&lt;Integer&gt;();
      list = new ArrayList&lt;Integer&gt;();
    }
  
    public void add(int e) { // To add one more item
      list.add(e);
  
    }
  
    public int poll() { // To remove one item
      if(!list.isEmpty())
        sortListAndTransferToStack();
      System.out.println("st.peek(): " + st.peek());
      return st.pop();
  
    }
  
    private void sortListAndTransferToStack() {
      Collections.sort(list, Collections.reverseOrder());
      st.clear();
      for(int i=0; i&lt;list.size(); i++) {
        st.push(list.get(i));
      }
      list.clear();
    }
  
    public boolean isEmpty() { // To check whether the priority queue is empty.  Don't modify this method
      return st.isEmpty();
    }
  }
  </code></pre>