public static Vertex[] topologicalSort(DirectedGraph graph) {
        Set<Vertex> vertexSet = graph.getVertexSet();
        if (vertexSet.size() < 2) {
            return vertexSet.toArray(new Vertex[0]);
        }

        LinkedList<Vertex> sortedList = new LinkedList<Vertex>();
        TimeRecorder recorder = new TimeRecorder();

        for (Vertex vertex : vertexSet) {
            if (vertex.color == Vertex.Color.WHITE) {
                visitVertex(graph, vertex, recorder, sortedList);
            }
        }

        return sortedList.toArray(new Vertex[0]);
    }