private Stack<Vertex<T>> getDfsSorting(Graph graph) {

        Set<Vertex<T>> nonVisited = new HashSet<Vertex<T>>();
        nonVisited.addAll(graph.getVertices());

        Stack<Vertex<T>> stack = new Stack<Vertex<T>>();
        //stack with vertices in order that corresponds to DFS run

        while (nonVisited.size() > 0) {

            Vertex<T> next = nonVisited.contains(new Vertex("A")) ? graph.getVertex(new Vertex("A")): nonVisited.iterator().next();
            stack.push(next);

            while (!stack.isEmpty()) {

                Vertex<T> vertex = stack.pop();
                nonVisited.remove(vertex);
                sorted.add(vertex);
                for (Edge<T> edge : vertex.getEdges()) {
                    if (nonVisited.contains(edge.getVertex2())) {
                        stack.push(edge.getVertex2());


                    }

                }
            }
            sorted.add(next);
        }

        if (sorted.size() != graph.getVertices().size()) {
            throw new RuntimeException("Wrong DFS sorting");
        }
        return new Stack<Vertex<T>>();
    }