|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 _2_ 于 2020-4-6 23:16 编辑
- class linked:
- """
- Linked list.
- """
- def __init__(self, *args):
- self.linkedList = [each for each in args]
- def make_a_linked(self):
- a = self.linkedList[0]
- b = self.linkedList[1]
- self.linkedDict = {}
- while 1:
- self.linkedDict[a] = b
- if b == len(self.linkedList) - 1:
- return None
- a += 1
- b += 1
- def index(self, n):
- return self.linkedDict[n]
- def show(self):
- if not len(self.linkedList):
- raise ValueError("The 'Linkedlist' cannot be empty.")
- step = " -> "
- showList = [str(i) + step for i in self.linkedList]
- self.showStr = "".join(showList)
- self.showStr = self.showStr[:len(self.showStr) - 4]
- return self.showStr
复制代码
我想到的就这么多,
如果有错误或意见(方法补充),请留言告诉我 |
|