Lecture Data Structures & Algorithms: Chapter 5
lượt xem 3
download
Lecture Data Structures & Algorithms: Chapter 5 Linked Lists presented the Concept Of The Linked List, Single Linked List, Double Linked List, Circular Linked List.
Bình luận(0) Đăng nhập để gửi bình luận!
Nội dung Text: Lecture Data Structures & Algorithms: Chapter 5
- DONG NAI UNIVERSITY OF TECHNOLOGY Data Structures & Algorithms 1
- DONG NAI UNIVERSITY OF TECHNOLOGY Linked Lists 2
- DONG NAI UNIVERSITY OF TECHNOLOGY The Concept Of The Linked List Single Linked List Double Linked List Circular Linked List 3
- DONG NAI UNIVERSITY OF TECHNOLOGY The Concept Of The Linked List - The size requirement need not be known at compile time. - A linked list is a data structure that is used to model such a dynamic list of data items, so the study of the linked lists as one of the data structures is important. 4
- DONG NAI UNIVERSITY OF TECHNOLOGY ARRAY Linked List - Sequential - An element is mapping, elements required to be are fixed distance linked with a apart. previous element - Makes insertion or of the list. deletion at any - Done by storing arbitrary position in the address of the an array a costly next element operation 5
- DONG NAI UNIVERSITY OF TECHNOLOGY M[0] M[1] M[2] M[3] M[4] M[5] M[6] 5 2 9 7 6 0 8 Data pNext Data pNext Data pNext Data pNext 6
- 4 things when build Linked DONG NAI UNIVERSITY OF TECHNOLOGY 1. List - Data element - Link field element Structure 2. Make linking between elements: - First, Last, Middle element 3. How many node to take all list elements, How to take all list. 4. Basic operations: - Insert new element (every position) - Delete (every position) - Count, Search, Sort, DeAllocated… 7
- DONG NAI UNIVERSITY OF TECHNOLOGY Single Linked List Data pNext Data pNext NULL Data pNext Data pNext 8
- DONG NAI UNIVERSITY OF TECHNOLOGY 1. Structure struct Node { int data; Node *pNext; }; 9
- DONG NAI UNIVERSITY OF TECHNOLOGY How to use node? Node node1; Node *node2; node2 =new Node(); node1.data=10; if(node2==NULL)exit(0); node1.pNext=NULL; node2->data=20; node2->pNext=NULL; cout
- DONG NAI UNIVERSITY OF TECHNOLOGY 2. The way to make link between elements First, last, middle element data pNext data pNext data pNext data pNext NULL Head Middle Last 11
- DONG NAI UNIVERSITY OF TECHNOLOGY pTail 3. How many node to take all list elements, how to take all list?pNext data data pNext data pNext data pNext NULL Why? • +from pHead, can we list all items? pHead • +from pHead, can we do everything with list: insert new, delete? • +Do we need pTail? 12
- DONG NAI UNIVERSITY OF TECHNOLOGY 4. Basic operations: Initialize PrintList CreateNode SumOfList InsertFirst SizeOfList InsertLast SearchNode InsertMid SortList RemoveNode FreeMemory pHead only or pHead & pTail ??? 13
- DONG NAI UNIVERSITY OF TECHNOLOGY Using pHead only 14
- DONG NAI UNIVERSITY OF TECHNOLOGY Initialize typedef struct Node { int data; Node *pNext; }; typedef struct SingleList { Node *pHead; }; void Initialize(SingleList &list) { list.pHead=NULL; } 15
- DONG NAI UNIVERSITY OF TECHNOLOGY Node *CreateNode(int d) CreateNode { Node *pNode=new Node; if(pNode!=NULL) pNode { pNode->data=d; Data pNext NULL pNode->pNext=NULL; } else { cout
- DONG NAI UNIVERSITY OF TECHNOLOGY InsertFirst pHead 8 pNext 9 pNext 5 pNext NULL pNode 3 pNext NULL pHead 8 pNext 9 pNext 5 pNext NULL pNode 3 pNext pHead pNode 3 pNext 8 pNext 9 pNext 5 pNext NULL 17
- DONG NAI UNIVERSITY OF TECHNOLOGY InsertFirst void InsertFirst(SingleList &list,int d) { Node *pNewNode=CreateNode(d); if(list.pHead==NULL) { list.pHead=pNewNode; } else { pNewNode->pNext=list.pHead; list.pHead=pNewNode; } } 18
- DONG NAI UNIVERSITY OF TECHNOLOGY pHead InsertLast 8 pNext 9 pNext 5 pNext NULL pNode 3 pNext NULL pHead 8 pNext 9 pNext 5 pNext pNode 3 pNext NULL pHead pNode 8 pNext 9 pNext 5 pNext 3 pNext NULL 19
- DONG NAI UNIVERSITY OF TECHNOLOGY InsertLast void InsertLast(SingleList &list,int d) { Node *pNewNode=CreateNode(d); if(list.pHead==NULL) { list.pHead=pNewNode; } else { Node *pTmp=list.pHead; while(pTmp->pNext!=NULL) { pTmp=pTmp->pNext; } pTmp->pNext=pNewNode; } 20
CÓ THỂ BẠN MUỐN DOWNLOAD
-
Lecture Data Structures & Algorithms: Chapter 1
22 p | 48 | 4
-
Lecture Data Structures & Algorithms: Chapter 0
9 p | 43 | 2
-
Lecture Data Structures: Lesson 38
71 p | 16 | 2
-
Lecture Data Structures: Lesson 36
24 p | 19 | 2
-
Lecture Data Structures: Lesson 41
18 p | 21 | 2
-
Lecture Data Structures: Lesson 32
16 p | 16 | 2
-
Lecture Data Structures: Lesson 26
30 p | 16 | 2
-
Lecture Data Structures: Lesson 30
21 p | 14 | 1
-
Lecture Data Structures: Lesson 40
11 p | 12 | 1
-
Lecture Data Structures: Lesson 39
17 p | 11 | 1
-
Lecture Data Structures: Lesson 37
22 p | 16 | 1
-
Lecture Data Structures: Lesson 27
24 p | 20 | 1
-
Lecture Data Structures: Lesson 35
20 p | 12 | 1
-
Lecture Data Structures: Lesson 34
14 p | 20 | 1
-
Lecture Data Structures: Lesson 28
26 p | 14 | 1
-
Lecture Data Structures: Lesson 29
20 p | 14 | 1
-
Lecture Data Structures: Lesson 31
16 p | 13 | 1
-
Lecture Data Structures: Lesson 33
14 p | 19 | 1
Chịu trách nhiệm nội dung:
Nguyễn Công Hà - Giám đốc Công ty TNHH TÀI LIỆU TRỰC TUYẾN VI NA
LIÊN HỆ
Địa chỉ: P402, 54A Nơ Trang Long, Phường 14, Q.Bình Thạnh, TP.HCM
Hotline: 093 303 0098
Email: support@tailieu.vn