/**
 * Company
 * Copyright (C) 2014-2017 All Rights Reserved.
 */
package com.cwenao.datastructure.graph;

import java.util.Queue;

/**
 * @author cwenao
 * @version $Id DepthFirstOrder.java, v 0.1 2017-09-14 18:20 cwenao Exp $$
 */
public class DepthFirstOrder {
    private boolean[] marked;
    private int[] pre;
    private int[] post;

    private Queue<Integer> preOrder;
    private Queue<Integer> postOrder;

    private int preCounter;
    private int postCounter;

}

@@ -101,16 +101,45 @@
 graph;%0A%0A
+import java.util.ArrayDeque;%0A
 import j
@@ -499,10 +499,922 @@
 unter;%0A%0A
+    public DepthFirstOrder(DirectedGraph graph) %7B%0A        pre = new int%5Bgraph.getV()%5D;%0A        post = new int%5Bgraph.getV()%5D;%0A        preOrder = new ArrayDeque%3C%3E();%0A        postOrder = new ArrayDeque%3C%3E();%0A        marked = new boolean%5Bgraph.getE()%5D;%0A%0A        for (int v = 0; v %3C graph.getV(); v++) %7B%0A            if (!marked%5Bv%5D) %7B%0A                dfs(graph,v);%0A            %7D%0A        %7D%0A%0A    %7D%0A%0A    private void dfs(DirectedGraph graph, int v) %7B%0A        marked%5Bv%5D = true;%0A        pre%5Bv%5D = preCounter++;%0A        preOrder.offer(v);%0A%0A        for (int w : graph.ajd(v)) %7B%0A            if (!marked%5Bw%5D) %7B%0A                dfs(graph, w);%0A            %7D%0A        %7D%0A    %7D%0A%0A    public int pre(int v) %7B%0A        return pre%5Bv%5D;%0A    %7D%0A%0A    public int post(int v) %7B%0A        return post%5Bv%5D;%0A    %7D%0A%0A    public Iterable%3CInteger%3E pre() %7B%0A        return preOrder;%0A    %7D%0A%0A    public Iterable%3CInteger%3E post() %7B%0A        return postOrder;%0A    %7D%0A
 %7D%0A

update the depth first order