Skip to content

Commit

Permalink
add missing files
Browse files Browse the repository at this point in the history
  • Loading branch information
shellfly committed Dec 19, 2021
1 parent e21b863 commit 54a920d
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 16 deletions.
59 changes: 59 additions & 0 deletions algs4/edge_weighted_directed_cycle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""
* Execution: python edge_weighted_directed_cycle.py V E F
* Data files: https://algs4.cs.princeton.edu/43mst/tinyEWG.txt
* https://algs4.cs.princeton.edu/43mst/mediumEWG.txt
* https://algs4.cs.princeton.edu/43mst/largeEWG.txt
*
* Finds a directed cycle in an edge-weighted digraph.
* Runs in O(E + V) time..
*
*
"""
from algs4.bag import Bag
from algs4.directed_edge import DirectedEdge


class EdgeWeightedDirectedCycle:
def __init__(self, v=0, **kwargs):
self.V = v
self.E = 0
self.adj = {}
for v in range(self.V):
self.adj[v] = Bag()

if 'file' in kwargs:
# init a digraph by a file input
in_file = kwargs['file']
self.V = int(in_file.readline())
for v in range(self.V):
self.adj[v] = Bag()
E = int(in_file.readline())
for i in range(E):
v, w, weight = in_file.readline().split()
self.add_edge(DirectedEdge(int(v), int(w), float(weight)))

def __str__(self):
s = "%d vertices, %d edges\n" % (self.V, self.E)
for i in range(self.V):
adjs = " ".join([str(x) for x in self.adj[i]])
s += "%d: %s\n" % (i, adjs)
return s

def add_edge(self, e):
self.adj[e.From()].add(e)
self.E += 1

def edges(self):
edges = []
for v in range(self.V):
for e in self.adj[v]:
edges.append(e)
return edges


if __name__ == "__main__":
import sys
V, E, F = sys.argv[1:]
graph = EdgeWeightedDirectedCycle(int(V), int(E), int(F))

print(graph)
31 changes: 15 additions & 16 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,25 @@

here = path.abspath(path.dirname(__file__))

with open(path.join(here, 'README.md'), encoding='utf-8') as f:
with open(path.join(here, "README.md"), encoding="utf-8") as f:
long_description = f.read()

setup(
name='algs4',
version='1.0.1',
description='A Python implementation library for book algs4',
name="algs4",
version="1.0.2",
description="A Python implementation library for book algs4",
long_description=long_description,
long_description_content_type='text/markdown',
url='https://github.com/shellfly/algs4-py',
author='shellfly',
author_email='[email protected]',
long_description_content_type="text/markdown",
url="https://github.com/shellfly/algs4-py",
author="shellfly",
author_email="[email protected]",
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'Topic :: Software Development :: Build Tools',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3',
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Topic :: Software Development :: Build Tools",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
],

keywords='algs4 algorithm', # Optional
packages=['algs4']
keywords="algs4 algorithm", # Optional
packages=["algs4", "algs4.utils"],
)

0 comments on commit 54a920d

Please sign in to comment.