SuperVingo

Singly Linked List 본문

Computer Science[CS]/Data Structure[자료구조]

Singly Linked List

SuperVingo 2023. 12. 31. 05:53
728x90

Head : Linked List의 시작 노드를 가르키는 포인터
Node : 데이터를 가르키는 포인터(Data) + 다음 노드를 가르키는 포인터(Next)
마지막 Node의 Next : NULL


Search

node = *head;
while(!node) {
    if(node->data == want)
        return true;

    node=node->next;
}
return false;

Insertion

Case 1. Insertion at The Front

  1. 새로운 Node 생성(New)
  2. New->Next = Head
  3. Head = New

Case 2. Insertion after The Node

  1. 새로운 Node 생성(New)
  2. New->Next = Curr->Next
  3. Curr->Next = New

Case 3. Insertion at The End

  1. 새로운 Node 생성(New)
  2. End->Next = New

Deletion

Case 1. Deletion at The Front

  1. Head = Front->Next
  2. Free The Node

Case 2. Deletion after The Node

  1. Prev->Next = Curr->Next
  2. Free The Node

Case 3. Deletion at The End

  1. Prev->Next = NULL
  2. Free The Node
728x90

'Computer Science[CS] > Data Structure[자료구조]' 카테고리의 다른 글

Self-balancinig BST 자가 균형 이진 탐색 트리  (0) 2024.01.04
Tree / BST  (1) 2024.01.03
Stack, Queue  (1) 2024.01.01
Doubly Linked List  (0) 2024.01.01
Circular Linked List  (0) 2024.01.01