Python实现--线性表-顺序存储结构--的基本运算

class SequenceList(): def __init__(self): self.SeqList = [] def createSequenceList(self): element = input('please input a numer and enter # ensure:') while element != '#': self.SeqList.append(int(element)) element = input('please input a numer and enter # ensure:') print self.SeqList def find_element(self): key = input('please input the element you want find:') if key in self.SeqList: key_pos = self.SeqList.index(key) print 'find num index is :%d'%key_pos else: print 'there is no such element!' def insert_element(self): pos = int(input('input the position to insert:')) key = int(input('input the data to insert')) print 'before inset the list is :',self.SeqList self.SeqList.insert(pos,key) print 'after insert the list is :',self.SeqList def delete_element(self): pos = int(input('input the position to delete:')) print 'before delete the list is :', self.SeqList if (pos < len(self.SeqList) and pos >=0): del self.SeqList[pos] print 'after delete the list is :', self.SeqList else: print 'out of index' def traverse_element(self): for i in range(len(self.SeqList)): print self.SeqList[i] def getextreme_element(self): value = https://www.it610.com/article/int(input('input 0 get min and input 1 get max:')) if value =https://www.it610.com/article/= 0: print'the min value is :',min(self.SeqList) elifvalue =https://www.it610.com/article/= 1: print'the max value is :',max(self.SeqList) else: print 'out of range!' def get_element(self): print 'current list is :',self.SeqList pos = int(input('input the position of element:')) if pos= 0 : print 'the element is:',self.SeqList[pos] else: print 'out of range!' def is_empty(self): print 'current list is :',self.SeqList if len(self.SeqList == 0): print 'list is empty!' else: print 'list is not empty!' def destory_list(self): print 'before destory list is :', self.SeqList self.__init__() print 'after destory list is :', self.SeqList list1 = SequenceList() list1.createSequenceList() #list1.find_element() #list1.insert_element() #list1.delete_element() #list1.traverse_element() #list1.getextreme_element() list1.destory_list()

    推荐阅读