数据结构——链表,数据结构,[Python]代码#u
数据结构——链表,数据结构,[Python]代码#u
[Python]代码
#utf-8import osclass Head_List: def __init__(self , id): self.id = id self.next = -1 self.length = 0 def setNext(self , value): self.next = value def addLength(self): self.length = self.length + 1 def displayLength(self): print self.length def displayAll(self): print 'head , id:' + str(self.id) + ' , next:' + str(self.next) #def getLastNode(self):class Node_List: def __init__(self , id , data): self.next = -1 self.data = data self.id = id def setNext(self , value): self.next = value def displayAll(self): print 'node , id:' + str(self.id) + ' , data:' + str(self.data) + ' , next:' + str(self.next)def addNode(head , node): node.next = head.next head.next = node.iddef delNode(node_one , node_two): node_one.next = node_two.next#main funtionsample = [38.6 , 47.6 , 53.7 , 54.9 , 55 , 80]hl = range(6)nl = range(6)for i in range(0,6,1): hl[i] = Head_List(i) nl[i] = Node_List(i , sample[i])for i in range(0,6,1): if i == 0: hl[0].setNext(nl[i].id) hl[0].addLength() continue else: for j in range(0,6,1): if (int(nl[i].data - 35) / 5 ) == int((nl[hl[j].next].data - 35) / 5 ): addNode(hl[j] , nl[i]) hl[j].addLength() break else: if hl[j].next == -1: addNode(hl[j] , nl[i]) hl[j].addLength() breakfor i in range(0,6,1): hl[i].displayAll()for i in range(0,6,1): nl[i].displayAll()
相关内容
- 冒泡排序(参考Discrete Mathematics and Its Application一书中的
- 上传文件,,[Python]代码<!
- python telnet登陆RouterOS执行相关命令,并返回命令执行结
- 利用bs4获取58同城城市分类,bs4获取58同城,python beaut
- Python 处理图像几何变换,python图像几何变换,[Python]代码
- python urllib2和httplib请求的速度比较实例测试,urllib2ht
- 使用python下载网页上的flash,pythonflash,[Python]代码''
- Python 批量获取《oschina》高亮代码区域源码!,python《
- Find bridges of graph,bridgesgraph,[Python]代码#
- 用Python实现一个简单的算术游戏,python实现算术,#!/us
评论关闭