Engaged Employer
coding: use two stacks to implement a queue
Anonymous
public class Queue{ private Stack inbox = new Stack(); private Stack outbox = new Stack(); public void queue(E item) { inbox.push(item); } public E dequeue() { if (outbox.isEmpty()) { while (!inbox.isEmpty()) { outbox.push(inbox.pop()); } } return outbox.pop(); } }
Check out your Company Bowl for anonymous work chats.