employer cover photo
employer logo

Frage im Vorstellungsgespräch bei VMware

Implement a queue using stack.

Antworten zu Vorstellungsgespräch

Anonym

23. Juni 2015

Don't you need to call flipStacks() again after s2.pop()?

Anonym

23. Mai 2015

public class QueueWithSTack { private Stack s1 = new Stack(); private Stack s2 = new Stack(); public synchronized void add(T item) { s1.push(item); } public synchronized T remove() { flipStacks(); return s2.pop(); } private void flipStacks() { while (!s1.isEmpty()) { T item = s1.pop(); s2.push(item); } } }