码迷,mamicode.com
首页 > 编程语言 > 详细

python 线性表顺序存储结构实现

时间:2014-09-26 01:09:08      阅读:525      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   sp   div   on   c   

 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()

今天有点晚了,明天进行总结更新··········

 

python 线性表顺序存储结构实现

标签:style   blog   color   io   ar   sp   div   on   c   

原文地址:http://www.cnblogs.com/loster/p/3994008.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!