Commit b13e2f60 by BellCodeEditor

auto save

parent 5e17500f
Showing with 56 additions and 1 deletions
# 用一个字典来表示无向图,节点为key,邻接点组成的list为value
graph = {
'A': ['B', 'C'],
'B': ['A', 'C', 'D'],
'C': ['A', 'B', 'D', 'E'],
'D': ['B', 'C', 'E', 'F'],
'E': ['C', 'D'],
'F': ['D']
}
def find_shortest_path(graph: dict, start_point):
"""
:param graph: 传进来的图
:param start_point: 起始节点
:return:
"""
queue = []
queue.append(start_point)
# 储存已经访问过的节点
seen = set()
seen.add(start_point)
# 存储上一个节点
parent = {start_point: None}
while len(queue) > 0:
point = queue.pop(0)
nodes = graph[point]
for node in nodes:
# 如果这个节点没有被访问过
if node not in seen:
queue.append(node)
seen.add(node)
parent[node] = point
# print(point)
return parent
if __name__ == '__main__':
parent_dict = find_shortest_path(graph, "A")
end = "E"
while end != None:
print(end, end='<-')
end = parent_dict[end]
import turtle
b=int(turtle.textinput("",""))
turtle.bgcolor()
turtle.colormode(255)
a.bgcolor(0,255,230)
turtle.color("red")
turtle.begin_fill()
turtle.circle(100)
turtle.end_fill()
turtle.done()
\ No newline at end of file
File added
......@@ -11,6 +11,7 @@ class Note(): # 便签、笔记
self.root.resizable(width=False, height=False)
def show(self): # 布置窗口界面
# 输入框
self.ent = tkinter.Entry(self.root, show=None,
font=('宋体', 13), bg="snow", width=25)
......@@ -21,7 +22,8 @@ class Note(): # 便签、笔记
self.but.place(x=240, y=305)
def get_info(self):
pass
kk=self.ent.get()
app = Note()
app.show()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment