-
大小: 0.02M文件類型: .py金幣: 1下載: 0 次發(fā)布日期: 2021-03-03
- 語言: Python
- 標(biāo)簽:
資源簡介
8數(shù)碼問題的python解決方案(代碼)
代碼片段和文件信息
from?queue?import?Queue
import?copy
‘‘‘設(shè)置數(shù)據(jù)結(jié)構(gòu)‘‘‘
class?Node:
????layout=[]
????depth=-1
????parent=None
????price=-1
????def?__init__(selfparentlayout=[]depth=-1price=-1):
????????self.layout=layout
????????self.depth=depth
????????self.parent=parent
????????self.price=price
????def?__repr__(self):
????????‘‘‘用來定義Node的字符輸出,print為輸出data‘‘‘
????????if?len(self.layout)==3:
????????????string=str(self.layout[0])+‘\n‘+str(self.layout[1])+‘\n‘+str(self.layout[2])
????????????return?string
????????else:
????????????return?str(self.layout)
????def?setLayout(selflayout):
????????self.layout=layout
????????return?layout
????def?setDeepth(selfdeepth):
????????self.depth=deepth
????????return?deepth
????def?setParent(selfparent):
????????self.parent=parent
????????return?parent
????def?setPrice(selfprice):
????????self.price=price
????????return?price
????def?hasParent(self):
????????return?self.parent?is?not?None
????def?toString(self):
?
評論
共有 條評論