refine BFS and DFS to fix the bug of accessing empty queue, Astar still has that problem