Good answer:You can use two stacks:an "incoming" stack and an "outgoing" stack.The enqueue and dequeue operations would look like this(in Java):Stack in;Stack out;void enqueue(int value) { while (!out.isEmpty()) in.push(out.pop()); in.push(value);}int dequeue() { while (!in.isEmpty()) out.push(in.pop()); return out.pop();}
共 1 个关于本帖的回复 最后回复于 2013-7-30 17:45