INPUT:-
mainlist:[12345,23456,09768]
Need to construct the following dependency graph
12345 has 01242(internal dep),34567(externaldep)
01242 has 23456(internaldep),56789,32345(externaldep)
34567 has 11111(internal dep),no external dependencies
23456 has 33456(internaldep),no external dependencies
56789 no dependencies
32345 no dependencies
11111 no dependencies
33456 no dependencies
09768 has 12222(internal dep),34333(External dep)
12222 no dependencies
34333 no dependencies
OUTPUT:-
[12345,01242,34567,23456,56789,32345,11111,33456,09768,12222,34333]
我有一些数据库对象,它们像上面的依赖项一样相互完全链接......我想做的是编写一个算法来检索该信息并将所有这些表示为一个图形。现在我正在编写一个伪代码,然后我应该能够编写 python 实现这似乎是一个递归算法,这就是我卡住的地方!
对于主列表中的每个项目,我试图递归地找出内部依赖和外部依赖,直到没有依赖并创建一个包含所有更改的列表。
build_dep_list=[]
local_list=[]
for each item in mainlist:
local_list.append(item)
build_dep_list.append(item)
for each localitem in local_list:
head = localitem
internal_dep_list =getinternaldep(change)
external_dep_list= getexternaldep(change)
append.internal_dep_list.local_list
append.external_dep_list.local_list
append.internal_dep_list.build_dep_list
append.external_dep_list.build_dep_list
delete(head).local_list
def getinternaldep:
//code1
def getexternaldep:
//code2