Selaa lähdekoodia

First commit

master
Pete Shadbolt 8 vuotta sitten
commit
bf1e2a2547
2 muutettua tiedostoa jossa 85 lisäystä ja 0 poistoa
  1. +57
    -0
      .gitignore
  2. +28
    -0
      abp.py

+ 57
- 0
.gitignore Näytä tiedosto

@@ -0,0 +1,57 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# PYC
*.pyc

+ 28
- 0
abp.py Näytä tiedosto

@@ -0,0 +1,28 @@
class Vertex(object):
def __init__(self):
self.neighbors = set()

def __str__(self):
return "v: {}".format(", ".join(map(str, self.neighbors)))

class GraphRegister(object):
def __init__(self, n):
self.vertices = [Vertex() for i in xrange(n)]

def add_edge(self, v1, v2):
self.vertices[v1].neighbors.add(v2)
self.vertices[v2].neighbors.add(v1)


def del_edge(self, v1, v2):
self.vertices[v1].neighbors.remove(v2)
self.vertices[v2].neighbors.remove(v1)

def __str__(self, ):
return "\n".join(str(v) for v in self.vertices)

if __name__ == '__main__':
g = GraphRegister(10)
g.add_edge(0,1)
print g


Loading…
Peruuta
Tallenna