본문 바로가기
Python/Python Examples

[Python] Linked List example code #01

by Henry Cho 2020. 10. 2.
728x90
class Node:
    def __init__(self, datavalue=None):
        self.datavalue = datavalue
        self.nextvalue = None

class LinkedList:
    def __init__(self):
        self.headvalue = None

    def listprint(self):
        printvalue = self.headvalue
        while printvalue is not None:
            print (printvalue.datavalue)
            printvalue = printvalue.nextvalue

list = LinkedList()
list.headvalue = Node("Howdi y'all.")
l2 = Node("Welcome to HOOAI!")
l3 = Node("미국남부형 likes an iced americano.")
l4 = Node("Thank you.")

list.headvalue.nextvalue = l2

l2.nextvalue = l3
l3.nextvalue = l4

list.listprint()
728x90

댓글