How to print the elements of a linked list?

后端 未结 2 586
一生所求
一生所求 2020-12-19 12:17

I\'m dong a Node exercise on python today. I seem to have accomplished a part of it, but it is not a complete success.

class Node:
    def __init__(self, ca         


        
相关标签:
2条回答
  • 2020-12-19 12:43

    Instead of calling str() on the node, you should access it's cargo:

    .
    .
    .    
    while node:
        nodelist.append(node.cargo)
        node = node.next
    .
    .
    .
    
    0 讨论(0)
  • 2020-12-19 13:04
    def printLinkedList(self):
        node = self.head
        while node != None:
            print(node.getData())
            node = node.getNext()
    
    0 讨论(0)
提交回复
热议问题