1 #!/usr/bin/env python2 #Conding=utf83 ImportSYS4 5 classlinelist:6 7 def __init__(self,length=11):8Self.list = []9Self.maxlength =lengthTen One definitlength (self,length,list): ASelf.maxlength =length -Self.list =List - the defListempty (self): - ifLen (self.list) = =0: - returnTrue - Else: + returnFalse - + defListfull (self): A ifLen (self.list) = = Self.maxlength-1: at returnTrue - Else: - returnFalse - - deflistclear (self): - ifSelf . Listempty (): in RaiseException ("Listisempty") - Else: toSelf.list = [] + - defListinsert (self,m,n): the ifSelf . Listfull (): * RaiseException ("Listisfull") $ Else:Panax Notoginseng ifM <0: - RaiseException ("m is error") the ifM >Len (self.list): + RaiseException ('m is error 2') A if(M >=0) and(M <=Len (self.list)): the Self.list.insert (m,n) + - defListdelete (self,x): $ ifSelf . Listempty (): $ RaiseException ('Listisempty') - Else: - ifX <0: the RaiseException ('x is Error1') - ifX >=Len (self.list):Wuyi RaiseException ('x is Error2') the if(x >= 0) and(X <Len (self.list)): - delSelf.list[x] Wu - deflistshow (self): About Printself.list $ - if __name__=="__main__": - -s =linelist () AS.initlength (8,[0,1,4]) +S.listinsert (6,'a') the s.listshow () -S.listdelete (5) $S.listshow ()
It's a little late today, and tomorrow is a summary update
Python linear table sequential storage structure implementation