연결리스트

각 노드가 데이터와 포인터를 가지고 연결되는 자료구조

구조

[head(10)] -> [next_node1(12)] -> [next_node2(20)]-> [tail(15)]

추가

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

head = Node(10)

next_node1 = Node(12)
head.next = next_node

next_node2 = Node(20)
next_node1.next = next_node2

tail = Node(15)
next_node2.next = tail

수정

next_node2.value = 35

삭제

head.next = next_node2

리스트 vs 연결리스트

리스트 연결리스트
접근/수정: 빠름 느림
삭제: 느림 빠름
메모리구조: 연속적 비연속적

더나아가

  1. 단일 연결리스트
  2. 이중 연결리스트
  3. 원형 연결리스트

댓글남기기