-2
我想將2個已排序的鏈接列表合併到單個已排序的鏈接列表中。Python:AttributeError:'NoneType'對象沒有屬性'數據'
class Node:
# Function to initialise the node object
def __init__(self, data):
self.data =data
self.next = None
class LinkedList:
def mergeNode(self, second_list):
llist4 = LinkedList()
first_node = self.head
second_node = second_list.head
while (first_node!=None or second_node != None):
if (first_node.data > second_node.data):
llist4.push(first_node)
prev = first_node
first_node = first_node.next
elif (first_node.data < second_node.data):
llist4.push(second_node)
prev = second_node
second_node = second_node.next
else:
llist4.push(first_node)
llist4.push(second_node)
prev = second_node
second_node = second_node.next
first_node = first_node.next
return llist4
if __name__ == '__main__':
llist = LinkedList()
llist2 = LinkedList()
llist3 = LinkedList()
llist.push(15)
llist.push(10)
llist.push(5)
llist2.push(12)
llist2.push(3)
llist2.push(2)
llist3 = llist.mergeNode(llist2)
llist3.printList()
但我得到的錯誤是:
" AttributeError: 'NoneType' object has no attribute 'data'"
我知道,我會在我的代碼使用無值由我無法找出原因。有人請幫我找出問題所在?
的可能的複製[Python的:屬性錯誤 - 'NoneType' 對象有沒有屬性 '東西'(http://stackoverflow.com/questions/8949252/ python-attribute-error-non-type-object-has-no-attribute-something) – intboolstring
我已經通過鏈接「Python:屬性錯誤 - 'NoneType'對象沒有屬性'東西'」我知道我正在嘗試使用我的代碼沒有任何價值,但我無法弄清楚原因。 – Vishal