I need to process a tree in different orders, let's say BFS and DFS. Both is easy by using a queue or a stack, however, I'm missing a proper interface in Java allowing to do something like
QueueOrStack<N> pending = ... while (!pending.isEmpty()) { N node = pending.poll(); // <----- this is the problem pending.addAll(node.children()); process(node); } There's no real problem, I can encapsulate an ArrayList into something implementing Queue1, however I'd bet I'm overlooking something in the Java Collection Framework. Or is it really missing?
__
1 or use a newest-first comparator with a PriorityQueue, which is probably a dumb idea