class SqList: #顺序表
def __init__(self): #构建空表
self.elem = []
def listAppend(self, item): #插入元素item在表尾
self.elem.append(item)
def listInsert(self, item,index): #在index之前插入元素item
self.elem.insert(index-1,item)
def listDelelte(self, index): #删除第index元素
del self.elem[index-1]
def dellast(self): #删除最后一个元素
self.elem.pop()
def length(self): #求表长
return len(self.elem)
def isEmpty(self): #判断表空
return self.elem == []
def traverse(self): #遍历顺序表
for item in self.elem:
print(item,end=' ')
print('\n')
#主函数
if__name__=='__main__':
list1=SqList()
for i in range(1,10):
list1.listAppend(i)
list1.traverse()
print("当前表长为{0}".format(list1.length()))
list1.listInsert(55,5)
list1.traverse()
list1.listDelelte(7)
list1.traverse()