Queue 2개로 Stack구현하기 import java.util.LinkedList; import java.util.Queue; public class Stack { private Queue q1; private Queue q2; public Stack() { this.q1 = new LinkedList(); this.q2 = new LinkedList(); } public void push(T value) { q1.add(value); } public T pop() { while (q1.size() > 1) { q2.add(q1.poll()); } Queue temp = q1; q1 = q2; q2 = temp; return q2.poll(); } @Override public String toStr..
Queue
Stack 두개를 이용하여 Queue구현하기 자바 import java.util.Stack; class Queue { Stack inStack; Stack outStack; public Queue() { this.inStack = new Stack(); this.outStack = new Stack(); } public void enqueue(T value) { inStack.add(value); } public T dequeue() { if (!inStack.isEmpty()) { while(!inStack.isEmpty()) { outStack.add(inStack.pop()); } } return outStack.pop(); } @Override public String toString() { re..