用户:
芙兰朵露_斯卡雷特查看:0 回复:0 评论:0 创建时间:2021-01-23T11:49:53
【作品展示】

【作品介绍】
使用散列表和广度优先算法
【作品源代码】
#算法5:散列表
#用散列表来检查人是否投过票
voted = {}
def check_voter(name):
if voted.get(name):
print("kick them out!")
else:
voted[name] = True
print("let them vote")
#用散列表来储存缓存
cache = {}
def get_page(url):
if cache.get(url):
return cache[url]
else:
data = get_data_from_server(url)
cache[url] = data
return data
#算法6:广度优先算法
#使用广度优先算法找芒果商
def search(name):
search_queue = deque()
search_queue += graph[name]
searched = []
while search_queue:
person = search_queue.popleft()
if not person in searched:
if person_is_seller(person):
print(person + " is a mango seller!")
return True
else:
search_queue += graph[person]
searched.append(person)
return False
search("you")
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn