1 #!/usr/bin/env python 2 # conding=utf8 3 import sys 4 5 class Linelist: 6 7 def __init__(self,length=11): 8 self.list = [] 9 self.maxlength = length 10 11 def Initlength(self,length,list): 12 self.maxlength = length 13 self.list = list 14 15 def Listempty(self): 16 if len(self.list) == 0: 17 return True 18 else: 19 return False 20 21 def Listfull(self): 22 if len(self.list) == self.maxlength - 1: 23 return True 24 else: 25 return False 26 27 def Listclear(self): 28 if self.Listempty(): 29 raise Exception("ListIsEmpty") 30 else: 31 self.list = [] 32 33 def Listinsert(self,m,n): 34 if self.Listfull(): 35 raise Exception("ListIsFull") 36 else: 37 if m < 0: 38 raise Exception("m is error") 39 if m > len(self.list): 40 raise Exception(‘m is error 2‘) 41 if (m >=0) and (m <= len(self.list)): 42 self.list.insert(m,n) 43 44 def Listdelete(self,x): 45 if self.Listempty(): 46 raise Exception(‘ListIsEmpty‘) 47 else: 48 if x < 0: 49 raise Exception(‘x is error1‘) 50 if x >= len(self.list): 51 raise Exception(‘x is error2‘) 52 if (x >= 0) and (x < len(self.list)): 53 del self.list[x] 54 55 def Listshow(self): 56 print self.list 57 58 if __name__ == "__main__": 59 60 s = Linelist() 61 s.Initlength(8,[0,1,4]) 62 s.Listinsert(6,‘a‘) 63 s.Listshow() 64 s.Listdelete(5) 65 s.Listshow()
今天有点晚了,明天进行总结更新··········
时间: 2024-10-07 04:47:07