Pythonリストアプリケーションのソースコードの例では、アプリケーションモジュールのPython OSメソッド、関数、クラスを使用する必要があります。
まず、簡単な最初に理解するために、リストには何ですか?リスト記憶部は、物理的に非連続、非連続の記憶構造、リンクされたリストの順にリンクポインタによって達成されるデータ要素の論理的な順序です。
次のようにPythonリストのアプリケーションのソースコードの例です。
#-*-coding:utf8 -*-
import os
class 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.id
def delNode(node_one , node_two):
node_one.next = node_two.next
#main funtion
sample = [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资源分享扣扣群:855408893 ,与你分享Python企业当下人才需求,怎么学Python,和学习什么内容!