DequeAdder tailAdder = new DequeAdder() { public void add(Vertex vertex, Deque<Vertex> deque) { deque.addLast(vertex); } }; DequeAdder headAdder = new DequeAdder() { public void add(Vertex vertex, Deque<Vertex> deque) { deque.addFirst(vertex); } };
tailAdder is used to implement BFS.
headAdder is used to implement DFS.