Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
485 B
3
Indexable
Never
class Node:

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

class LinkedList:

    def __init__(self):
        self.head = Node()

    def append(self, data):
        new_node = Node(data)
        cur = self.head
        while cur.next != None:
            cur = cur.next
        cur.next = new_node   

node1 = Node(42)
node2 = Node(5)
node1.next = node2
node2.next = node1

list1 = LinkedList()

print(list1.append(node1))