# Path: pyalgs/data_structures/commons/stack.py
# class Stack(object):
#     """ Stack interface which provides the API for stack data structure
#     """
# 
#     __metaclass__ = ABCMeta
# 
#     @abstractmethod
#     def push(self, item):
#         pass
# 
#     @abstractmethod
#     def pop(self):
#         pass
# 
#     @abstractmethod
#     def is_empty(self):
#         pass
# 
#     @abstractmethod
#     def size(self):
#         pass
# 
#     @abstractmethod
#     def iterate(self):
#         pass
# 
#     @staticmethod
#     def create():
#         return LinkedListStack()
# 
# Path: pyalgs/data_structures/graphs/graph.py
# class EdgeWeightedGraph(object):
#     adjList = None
#     V = 0
# 
#     def __init__(self, vertex_count):
#         self.V = vertex_count
#         self.adjList = [None] * vertex_count
#         for v in range(vertex_count):
#             self.adjList[v] = Bag()
# 
#     def add_edge(self, edge):
#         v = edge.either()
#         w = edge.other(v)
#         self.adjList[v].add(edge)
#         self.adjList[w].add(edge)
# 
#     def adj(self, v):
#         return self.adjList[v].iterate()
# 
#     def vertex_count(self):
#         return self.V
# 
#     def edges(self):
#         for v in range(self.V):
#             for e in self.adj(v):
#                 if e.either() == v:
#                     yield e
# 
#     def to_graph(self):
#         g = Graph()
# 
#         for e in self.edges():
#             g.add_edge(e.start(), e.end())
#         return g
# 
#     def to_edge_weighted_digraph(self):
#         g = DirectedEdgeWeightedGraph(self.V)
# 
#         for e in self.edges():
#             g.add_edge(e)
#             g.add_edge(e.reverse())
#         return g
# 
# class DirectedEdgeWeightedGraph(object):
#     adjList = None
#     V = 0
# 
#     def __init__(self, vertex_count):
#         self.V = vertex_count
#         self.adjList = [None] * vertex_count
#         for v in range(vertex_count):
#             self.adjList[v] = Bag()
# 
#     def add_edge(self, edge):
#         v = edge.start()
#         self.adjList[v].add(edge)
# 
#     def adj(self, v):
#         return self.adjList[v].iterate()
# 
#     def vertex_count(self):
#         return self.V
# 
#     def edges(self):
#         for v in range(self.V):
#             for e in self.adj(v):
#                 yield e
# 
#     def to_graph(self):
#         g = Graph()
# 
#         for e in self.edges():
#             g.add_edge(e.start(), e.end())
#         return g
# 
#     def to_digraph(self):
#         g = Digraph(self.V)
# 
#         for e in self.edges():
#             g.add_edge(e.start(), e.end())
# 
#         return g


from pyalgs.data_structures.commons.stack import Stack
from pyalgs.data_structures.graphs.graph import EdgeWeightedGraph, DirectedEdgeWeightedGraph


class DepthFirstOrder(object):

    marked = None
    reversePostOrder = None

    def __init__(self, G):
        if isinstance(G, DirectedEdgeWeightedGraph):
            G = G.to_digraph()


# Path: pyalgs/data_structures/commons/stack.py
# class Stack(object):
#     """ Stack interface which provides the API for stack data structure
#     """
# 
#     __metaclass__ = ABCMeta
# 
#     @abstractmethod
#     def push(self, item):
#         pass
# 
#     @abstractmethod
#     def pop(self):
#         pass
# 
#     @abstractmethod
#     def is_empty(self):
#         pass
# 
#     @abstractmethod
#     def size(self):
#         pass
# 
#     @abstractmethod
#     def iterate(self):
#         pass
# 
#     @staticmethod
#     def create():
#         return LinkedListStack()
# 
# Path: pyalgs/data_structures/graphs/graph.py
# class EdgeWeightedGraph(object):
#     adjList = None
#     V = 0
# 
#     def __init__(self, vertex_count):
#         self.V = vertex_count
#         self.adjList = [None] * vertex_count
#         for v in range(vertex_count):
#             self.adjList[v] = Bag()
# 
#     def add_edge(self, edge):
#         v = edge.either()
#         w = edge.other(v)
#         self.adjList[v].add(edge)
#         self.adjList[w].add(edge)
# 
#     def adj(self, v):
#         return self.adjList[v].iterate()
# 
#     def vertex_count(self):
#         return self.V
# 
#     def edges(self):
#         for v in range(self.V):
#             for e in self.adj(v):
#                 if e.either() == v:
#                     yield e
# 
#     def to_graph(self):
#         g = Graph()
# 
#         for e in self.edges():
#             g.add_edge(e.start(), e.end())
#         return g
# 
#     def to_edge_weighted_digraph(self):
#         g = DirectedEdgeWeightedGraph(self.V)
# 
#         for e in self.edges():
#             g.add_edge(e)
#             g.add_edge(e.reverse())
#         return g
# 
# class DirectedEdgeWeightedGraph(object):
#     adjList = None
#     V = 0
# 
#     def __init__(self, vertex_count):
#         self.V = vertex_count
#         self.adjList = [None] * vertex_count
#         for v in range(vertex_count):
#             self.adjList[v] = Bag()
# 
#     def add_edge(self, edge):
#         v = edge.start()
#         self.adjList[v].add(edge)
# 
#     def adj(self, v):
#         return self.adjList[v].iterate()
# 
#     def vertex_count(self):
#         return self.V
# 
#     def edges(self):
#         for v in range(self.V):
#             for e in self.adj(v):
#                 yield e
# 
#     def to_graph(self):
#         g = Graph()
# 
#         for e in self.edges():
#             g.add_edge(e.start(), e.end())
#         return g
# 
#     def to_digraph(self):
#         g = Digraph(self.V)
# 
#         for e in self.edges():
#             g.add_edge(e.start(), e.end())
# 
#         return g


# Path: pyalgs/algorithms/graphs/topological_sort.py
from pyalgs.data_structures.commons.stack import Stack
from pyalgs.data_structures.graphs.graph import EdgeWeightedGraph, DirectedEdgeWeightedGraph



class DepthFirstOrder(object):

    marked = None
    reversePostOrder = None

    def __init__(self, G):
        if isinstance(G, DirectedEdgeWeightedGraph):
            G = G.to_digraph()


        self.reversePostOrder = Stack.create()