class Linearlist(): def __init__(self,list,maxsize): self.data= list self.maxsize = maxsize self.length = len(self.data) def listinsert(self,i,e): if self.length == self.maxsize: print('runout allocated memory') raise AttributeError if i<1 or i>self.length + 1: print('attribute error:index surpassed!') raise AttributeError self.data.append(0) for c in range(self.length,i-1,-1): self.data[c] = self.data[c-1] self.data[i-1] = e self.length += 1 #test ob = Linearlist([1,2,3,7,8,9,10,11,12,13,14],20) print(ob.data) print(ob.length) ob.listinsert(20,17) print(ob.data)
顺序线性表插入功能实现--Python
猜你喜欢
转载自blog.csdn.net/baidu_39622935/article/details/79502039
今日推荐
周排行