python链表应用源码示例,python源码示例,python链表应用源码
python链表应用源码示例,python源码示例,python链表应用源码
python链表应用源码示例,需要用到python os模块方法、函数和类的应用。
首先,先简单的来了解下什么是链表?链表是一种物理存储单元上非连续、非顺序的存储结构,数据元素的逻辑顺序是通过链表中的指针链接次序实现的。
python链表应用源码示例如下:
#-*-coding:utf8 -*-import 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() break for i in range(0,6,1): hl[i].displayAll()for i in range(0,6,1): nl[i].displayAll()
编橙之家文章,
相关内容
- Python抓取分享页面的源代码示例,python抓取,本文章是关
- Python提取嵌套文件夹下指定文件操作源码,,如何在多重
- 5个常用的Python功能代码,python功能代码,今天编橙之家
- 用Python合并多个文件为一个文本文件的方法代码,pyt
- Python读取分割压缩TXT文本文件的方法,pythontxt,本文为大
- 用Python实现一个简单的线程池模型效果代码分析讲解,
- linux系统more基本命令python源码分享,linuxpython,此贴pyt
- Python 使用http时间同步设置系统时间源码,python源码,
- python代码来登陆网站签到米粒VPN,pythonvpn,python代码来登
- 第四章之得到更多信息:type(),,
评论关闭