int main ()
{
    std::ostringstream strm [32];
    const std::size_t N = sizeof strm / sizeof *strm;

    for (std::size_t i = 0; i != N; ++i) {

        // tie the first i streams together in a circular list
        tie (strm, i);

        assert (0 == i || is_cycle (strm));

        for (std::size_t j = 0; j != i; ++j) {

            // make sure formatted and unformatted output for
            // each of the tied streams works without getting
            // into a deadlock or into infinite recursion
            strm [j] << j;
            strm [j].flush ();

            assert (strm [j].good ());
        }
    }

    return 0;
}
Пример #2
0
int main () {

	int V = 3;
	int E = 3;

	Graph* graph = build_graph(V, E);
	graph->edges[0].src = 0;
	graph->edges[0].dest = 1;
	graph->edges[1].src = 1;
	graph->edges[1].dest = 2;
	graph->edges[2].src = 0;
	graph->edges[2].dest = 2;
	if (is_cycle(graph)) {
		printf("Cycle detected.");
	} else {
		printf("No cycle detected.");
	}
	return 0;
}