Stack225ImplementStackUsingQueues

思路

  • Make push() inefficient
  • Make pop() and peek() inefficient
  • Rotate the queue itself in push()

Bug

  • Method 3: rotate the queue.
    • Rotate time is q.size() - 1 rather than q.size() times. Make the last element to the head!
for (int i = 1; i < q1.size(); i++) {
    q1.add(q1.poll());
 }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章