Singly Linked List 구현은 매우 간단하고, 자주 사용하게 되므로 알아두는 것이 좋다.
# Singly Linked List class 정의
class Node:
def __init__(self, val):
self.val = val
self.next = None
# '0'이라는 데이터를 담은 head와 cursor 선언
cur = head = Node(0)
# '1'이라는 데이터를 담은 새로운 Node 선언해 head의 다음으로 연결
new = Node(1)
cur.next = new
cur = new
# head부터 출력하면 0, 1을 출력으로 확인 가능
test = head
while test:
print(test.val)
test = test.next
'기술(Tech, IT) > 파이썬(Python)' 카테고리의 다른 글
[Python] SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape (0) | 2024.01.06 |
---|---|
[Python] pickle (0) | 2023.12.28 |
[Python] 파이썬 정규 표현식 (정규식, Python's Regular Expression) (0) | 2023.08.17 |
[Python] re.split() (0) | 2023.08.16 |
[Python] numpy ones (0) | 2023.08.09 |