알고리즘/이론

[알고리즘] 링크드 리스트 append 구현

자바칩 프라푸치노 2021. 6. 13. 00:28

 

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

node = Node(3)
first_node = Node(4)
node.next = first_node
print(node.next.data)
class LinkedList:
    def __init__(self, data):
        self.head = Node(data)

class LinkedList:
    def __init__(self, data):
        self.head = Node(data)

    def append(self, data):
      
        if self.head is None:
            self.head = Node(data)
            return
        
        cur = self.head
        while cur.next is not None:
            cur = cur.next
        cur.next = Node(data)

 

728x90