190 likes | 494 Views
Data Structure: Chapter 5. Min Chen School of Computer Science and Engineering Seoul National University. Linked Lists. Content. Understanding Linked List Operators for Linked List Insert Remove Display Search Sorted Lists. Understanding Linked Lists.
E N D
Data Structure: Chapter 5 Min Chen School of Computer Science and Engineering Seoul National University Linked Lists
Content • Understanding Linked List • Operators for Linked List • Insert • Remove • Display • Search • Sorted Lists
Understanding Linked Lists • Defined by Relationship, not Position • For array, stack, queue • Relationship is represented by position • For linked list • Relationship is represented by links Value Field Link Field
Circular Lists • There is no end in Circular List • All items have next hop
Doubly Linked List • Shortcoming of singly linked list • Difficult to travel back! • Addressed by Doubly Linked List
Operators : Insert • Insert item into the linked list Fig.1 Insert Operator in Linked List
Operators : Remove • Remove item from the linked list Fig.2 Remove Operator in Linked List
Operators : Display • Display all the items in the linked list 21 3 87 238 46 379 Display: 87 Display: 46 Display: 21 Display: 3 Display: 238 Display: 379 Fig.3 Display Operator in Linked List
Operators : Search • Search value 238 in the linked list 21 3 87 238 46 379 Found 238 ! Fig.4 Search Operator in Linked List
Operators for Doubly Linked List • Similar to Singly Linked Lists • Pay attention to the link redirection
Sorted Lists • As implied by the name, the items in the sorted lists are sorted by a key as in ordered array 24 35 72 30