diff --git a/algs4/cycle.py b/algs4/cycle.py index 923e035..b6f6925 100644 --- a/algs4/cycle.py +++ b/algs4/cycle.py @@ -1,21 +1,19 @@ """ - Compilation: javac Cycle.java - Execution: java Cycle filename.txt - Dependencies: Graph.java Stack.java In.java StdOut.java - Data files: https: // algs4.cs.princeton.edu / 41graph / tinyG.txt - https: // algs4.cs.princeton.edu / 41graph / mediumG.txt - https: // algs4.cs.princeton.edu / 41graph / largeG.txt + Execution: python cycle.py filename.txt + Data files: https://algs4.cs.princeton.edu/41graph/tinyG.txt + https://algs4.cs.princeton.edu/41graph/mediumG.txt + https://algs4.cs.princeton.edu/41graph/largeG.txt Identifies a cycle. Runs in O(E + V) time. - % java Cycle tinyG.txt + % python cycle.py tinyG.txt 3 4 5 3 - % java Cycle mediumG.txt + % python cycle.py mediumG.txt 15 0 225 15 - % java Cycle largeG.txt + % python cycle.py largeG.txt 996673 762 840164 4619 785187 194717 996673 """ @@ -39,6 +37,7 @@ def dfs(self, G, v, u): elif w != u: self.has_cycle = True + if __name__ == "__main__": import sys f = open(sys.argv[1])