list 是一种元素个数可变的线性表,采用了分离式技术实现的动态顺序表。可以加入和删除元素,并在各种操作中维持已有元素的顺序(即保序)。
1.1 创建顺序表
1 2 3 4 5 6
# 创建顺序表 defCreateSeqList(self): element = input("please enter(input #:end):") while element != '#': self.seqList.append(int(element)) element = input("please enter(input #:end):")
1.2 查找元素
1 2 3 4 5 6 7 8 9
# 查找顺序表中某一个元素 defFindElement(self): key = int(input("please enter what you want to find:")) if key in self.seqList: keyPosition = self.seqList.index(key) result = keyPosition else: result = "none" return result
# 创建顺序表 defCreateSeqList(self): element = input("please enter(input #:end):") while element != '#': self.seqList.append(int(element)) element = input("please enter(input #:end):")
# 查找顺序表中某一个元素 defFindElement(self): key = int(input("please enter what you want to find:")) if key in self.seqList: keyPosition = self.seqList.index(key) result = keyPosition else: result = "none" return result