Created
January 11, 2023 11:25
-
-
Save pupba/843dbb06b187240f5e405699b6f4689d to your computer and use it in GitHub Desktop.
Direct, Undirect Graph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Direct Graph | |
class DGraph: | |
def __init__(self): | |
self.__nodes = {} | |
def add(self,name,edgelist): | |
# name , edgelist | |
self.__nodes[name] = edgelist | |
def remove(self,name): | |
del self.__nodes[name] | |
def printAll(self): | |
for data in self.__nodes.keys(): | |
print(f'{data} -> {self.__nodes[data]}') | |
# Undirect Graph | |
class UGraph: | |
def __init__(self): | |
self.__nodes = {} | |
def add(self,name,edgelist): | |
# [('A','B'),('A','C')] | |
self.__nodes[name] = edgelist | |
def remove(self,name): | |
del self.__nodes[name] | |
def printAll(self): | |
for data in self.__nodes.keys(): | |
print(f'{data}의 인접 리스트 : {[i[1] for i in self.__nodes[data]]}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment