1. 程式人生 > >python: 簡單單鏈表

python: 簡單單鏈表

class Node:
    def __init__(self, data, next=None):
        self.data = data
        self.next = next

    def __str__(self):
        return str(self.data)


head = None
for i in range(1, 6):
    head = Node(i, head)
while head != None:
    print(head.next)
    head = head.next