首页 > 代码库 > python 线性表顺序存储结构实现
python 线性表顺序存储结构实现
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 = length10 11 def Initlength(self,length,list):12 self.maxlength = length13 self.list = list14 15 def Listempty(self):16 if len(self.list) == 0:17 return True18 else:19 return False20 21 def Listfull(self):22 if len(self.list) == self.maxlength - 1:23 return True24 else:25 return False26 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.list57 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()
今天有点晚了,明天进行总结更新··········
python 线性表顺序存储结构实现
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。