def cost_graph_search(problem, container):
    """
    Define a graph search algorithm used for Uniform Cost Search & A* Search.
    Parameter:
    problem -> Class in searchAgents.py: The search problem we would want to solve.
    container -> The data structure(PriorityQueueWithFunction) that is used for solving the problem.
    """

    visited = []
    container.push([(problem.getStartState(), "Stop", 0)])
    while not container.isEmpty():
        path = container.pop()
        position = path[-1][0]

        if problem.isGoalState(position):
            return [i[1] for i in path][1:]

        if position not in visited:
            visited.append(position)

            for successor in problem.getSuccessors(position):
                if successor[0] not in visited:
                    successorPath = path[:]
                    successorPath.append(successor)
                    container.push(successorPath)

    return False