이중 연결 리스트(Doubly linked list)_구조

김지수·2021년 4월 16일
0

Data Structure

목록 보기
6/15
post-thumbnail

이중 연결 리스트(Doubly linked list)

이중 연결 리스트는 양방향으로 다음 노드와 이전 노드의 이동이 가능한 자료구조
head, tail로 리스트의 앞과 뒤로 접근이 가능함



코드

#이중 링크드 리스트
class DLinkedList:

    #D_L_list에서 쓸 노드
    class Node:
        def __init__(self, v, n = None, p = None):
            self.value = v #저장된 데이터
            self.next = n #다음 노드 가리키는 변수
            self.prev = p #이전 노드 가리키는 변수

    #D_L_List에서 필요한 변수
    def __init__(self):
        self.head = None #첫 생성시 내부에는 노드가 없음
        self.tail = None

##테스트
if __name__=="__main__":
    dl = DLinkedList()

설명

nextprevheadtail
다음에 연결된 노드를 가리키는 변수이전의 노드를 가리키는 변수맨 처음 노드를 가리키는 변수맨 마지막 노드를 가리키는 변수

참고
https://wikidocs.net/34342

profile
A Data human as a Learner, a Supporter, and a Listener

0개의 댓글