Linked List 1 Singly Linked List Node key





![Singly Linked List • Array Implementation C E G J K key[ ] next[ Singly Linked List • Array Implementation C E G J K key[ ] next[](https://slidetodoc.com/presentation_image/5d10fb3ce6ad463923f3d6d368842e1a/image-6.jpg)



![Doubly Linked List • Array Implementation C E G J K P key[ ] Doubly Linked List • Array Implementation C E G J K P key[ ]](https://slidetodoc.com/presentation_image/5d10fb3ce6ad463923f3d6d368842e1a/image-10.jpg)



![Doubly Linked List • Implementation 1) Multiple Array key[ ], next[ ], prev[ ] Doubly Linked List • Implementation 1) Multiple Array key[ ], next[ ], prev[ ]](https://slidetodoc.com/presentation_image/5d10fb3ce6ad463923f3d6d368842e1a/image-14.jpg)


















![리스트 클래스 int _tmain(int argc, TCHAR* argv[ ], TCHAR* envp[ ]) { int n. 리스트 클래스 int _tmain(int argc, TCHAR* argv[ ], TCHAR* envp[ ]) { int n.](https://slidetodoc.com/presentation_image/5d10fb3ce6ad463923f3d6d368842e1a/image-33.jpg)

- Slides: 34

Linked List 1



Singly Linked List • 원소 (Node) 구성 key next pointer (1) Key field • 원소의 데이터 저장 (2) Pointer field • 다음 원소의 주소 저장 4

Singly Linked List • Data Member – L (list) : key fields + next pointer fields (next) – head[L] : list L 의 첫 원소의 주소 • List empty: head[L]= NIL • Last element: next[x] = NIL; head[L] / 5
![Singly Linked List Array Implementation C E G J K key next Singly Linked List • Array Implementation C E G J K key[ ] next[](https://slidetodoc.com/presentation_image/5d10fb3ce6ad463923f3d6d368842e1a/image-6.jpg)
Singly Linked List • Array Implementation C E G J K key[ ] next[ ] G 4 3 C 5 4 J 8 5 E 1 6 X NIL 8 K 9 9 P 6 1 P X 2 head[L]=3 7 10 6

Singly Linked List • Insert Operation – 주소 z 인 element 를 주소 x 의 element 다음에 삽입 x C E G (2) (1) z J K P X (1) next[z] = next[x] (2) next[x] = z F • Delete Operation – 주소 y 의 element 를 list에서 삭제 x C (1) E y G J K P X (1) next[x] = next[y] x 를 어떻게 찾나? ÞLIST-SEARCH ÞO(n) 7

Doubly Linked List • 원소 (Node) 구성 previous pointer key next pointer (1) Key field • 원소의 데이터 저장 (2) Next pointer field • 다음 원소의 주소 저장 (3) Previous pointer field • 직전 원소의 주소 저장 8

Doubly Linked List • Data Member – L (list) : key fields + next pointer fields (next) + previous pointer fields (prev) – head[L] : list L 의 첫 원소의 주소 • List empty: head[L]= NIL • Last element: next[x] = NIL • First element: prev[x] = NIL head[L] / 9
![Doubly Linked List Array Implementation C E G J K P key Doubly Linked List • Array Implementation C E G J K P key[ ]](https://slidetodoc.com/presentation_image/5d10fb3ce6ad463923f3d6d368842e1a/image-10.jpg)
Doubly Linked List • Array Implementation C E G J K P key[ ] next[ ] prev[ ] G 4 5 3 C 5 NIL 4 J 7 1 5 E 1 3 6 X NIL 9 8 K 9 4 9 P 6 8 1 X 2 head[L]=3 7 10 10

Doubly Linked List • LIST-INSERT( L, x) – list L 의 front 에 x 주소를 갖는 원소 삽입 – O(1) List non-empty 인 경우 (head[L] != NIL) (1) (2) (3) (4) head[L] (3) (4) (2) (1) x next[x] = head[L] prev[head[L]] = x head[L]=x prev[x]=NIL (2) List empty 인 경우 (head[L] = NIL) head[L] (3) (4) x (1) 11

Doubly Linked List • LIST-DELETE( L, x) – list L 의 x 주소에 있는 원소 삭제 – O(1) first element 가 아닌 경우 (1) next[prev[x]] = next[x] (2) prev[next[x]] = prev[x] x (2) first element 인 경우 (1) head[L] = next[x] (2) prev[next[x]] = prev[x] x (2) 12

Doubly Linked List • LIST-SEARCH(L, k) – list L 에서 key 값이 k 인 원소를 찾아, 그 주소 return – O(n) 13
![Doubly Linked List Implementation 1 Multiple Array key next prev Doubly Linked List • Implementation 1) Multiple Array key[ ], next[ ], prev[ ]](https://slidetodoc.com/presentation_image/5d10fb3ce6ad463923f3d6d368842e1a/image-14.jpg)
Doubly Linked List • Implementation 1) Multiple Array key[ ], next[ ], prev[ ] 3개의 array 사용 2) Single Array 하나의 array 사용 A[i] → key, A[i+1] → next, A[i+2] → prev 3) Node struct NODE{ int key; NODE* next; NODE* prev; }; NODE* head; 14

Rooted Tree Representation • Binary Tree – Left-child, right-child representation – Data member Node: key + parent pointer + left child pointer + right child pointer T: node 의 집합 Root[T]: root node 의 index 15

Rooted Tree Representation • 일반 Tree – Left-child, right-sibling representation – Data member Node: key + parent pointer + left child pointer + right sibling pointer T: node 의 집합 Root[T]: root node 의 index 16

Polynomials • Singly linked list 를 이용하여 다항식 표현 • 원소 (node) 구성 – Key field = coef (계수) + expo (지수) – Next pointer field = link (다음 항 연결) typedef struct Node { float coef; int expo; struct Node *link; }; 17

Polynomials • 표현 예 • A(x)=4 x 3+3 x 2+5 x • B(x)=3 x 4+x 3+2 x+1 ⇒ 효과적 메모리 사용 (cf) sequential list 18

Polynomials • Append. Term (PL, coef, expo, last) – 다항식의 항 1 개 (coef, expo) 를 추가하는 알고리즘 PL: list head last: list 마지막 노드의 주소 (ex) A(x)=4 x 3+3 x 2+5 x+2 19

Polynomials • Append Term 20





Polynomials • Addition Algorithm 25

Polynomials • Addition Results 26


리스트 클래스 • 비 템플릿 클래스 – afxcoll. h 헤더 파일 클래스 이름 데이터 타입 사용 예 COb. List CObject 포인터 COb. List list; CPtr. List void 포인터 CPtr. List list; CString. List list; 28


리스트 클래스 • 순환 // 리스트 제일 앞에서 출발하여 순환한다. POSITION pos = list. Get. Head. Position(); while(pos != NULL){ CString string = list. Get. Next(pos); cout << (LPCTSTR)string << endl; } cout << endl; // 리스트 제일 뒤에서 출발하여 순환한다. pos = list. Get. Tail. Position(); while(pos != NULL){ CString string = list. Get. Prev(pos); cout << (LPCTSTR)string << endl; } 30

리스트 클래스 • 항목 삽입과 삭제 // POSITION 타입의 변수 pos는 이전의 예제에서 선언한 것이다. pos = list. Find("포도"); list. Insert. Before(pos, "살구"); list. Insert. After(pos, "바나나"); list. Remove. At (pos); // 항목 삽입과 삭제 후 결과를 확인한다. pos = list. Get. Head. Position(); while(pos != NULL){ CString string = list. Get. Next(pos); cout << (LPCTSTR)string << endl; } 31

리스트 클래스 • 템플릿 리스트 클래스 #include "stdafx. h" #include "Console. h" #include <afxtempl. h> CWin. App the. App; using namespace std; struct Point 3 D { int x, y, z; Point 3 D() {} Point 3 D(int x 0, int y 0, int z 0) { x = x 0; y = y 0; z = z 0; } }; 32
![리스트 클래스 int tmainint argc TCHAR argv TCHAR envp int n 리스트 클래스 int _tmain(int argc, TCHAR* argv[ ], TCHAR* envp[ ]) { int n.](https://slidetodoc.com/presentation_image/5d10fb3ce6ad463923f3d6d368842e1a/image-33.jpg)
리스트 클래스 int _tmain(int argc, TCHAR* argv[ ], TCHAR* envp[ ]) { int n. Ret. Code = 0; if (!Afx. Win. Init(. . . )) { // 생략. . . } else { CList<Point 3 D, Point 3 D&> list; for(int i=0; i<5; i++) list. Add. Tail(Point 3 D(i, i*100)); POSITION pos = list. Get. Head. Position(); 33

리스트 클래스 } } while(pos != NULL) { Point 3 D pt = list. Get. Next(pos); cout << pt. x << ", " << pt. y << ", " << pt. z << endl; } return n. Ret. Code; 34
Node node 1 new Node node 1 data
ADT DINAMIS SINGLY LINKED LIST DAN DOUBLE LINKED
Linked Lists Singly doubly linked list XOR lists
Double Linked List Double Linked List Linked list
LINKED LIST Circular Linked List Circular Linked List
Single Linked List Linked List Linked List adalah
LISTS Pointers Singly Linked Lists Dynamically Linked Stacks
Single Linked List Single Linked List Single linked
Singly Linked Lists What is a singlylinked list
Inverting a Singly Linked List Instructor Prof JyhShing
DOM Document node html node body node h
Node 1 DB 1 Node 2 Node 3
list data list nil list link list list
Linked List outline Why linked lists Linked lists
Linked Lists C Linked List 1 A linked
Linked Lists C Linked List 1 A linked
Linked Lists C Linked List 1 A linked
4 List 1 typedef struct list Node list
Linked Lists in MIPS Lets see how singly
Linked Lists in MIPS Lets see how singly
Chapter 3 Arrays Linked Lists and Recursion Singly
Singly Linked Lists 5Peter 524Peter 4 next 6Peter
Singly Linked Lists Representation Space Analysis Creation and
Singly Linked Lists Representation Space Analysis Creation and
list stack struct node int info node next
node what 1node list int x node temp
Application of linked list Geletaw S Linked list
Double Linked List Double Linked List Sama seperti
Circular Linked List Introduction Circular linked list is
Linked List LINKED LIST Link is collection of
Building a Linked List in Java Linked List
STRUKTUR DATA 2 Single Linked List Linked List
Circular Linked List COMP 104 Circular Linked List
Linked Lists Linked list a list of items