Yan Shi CS/SE 2630 Lecture Notes

Slides:



Advertisements
Similar presentations
Sorted Lists CS Data Structures Sections 4.1, 4.2 & 4.3.
Advertisements

Alan YorinksLecture 7 1 • Tonight we will look at:: • List ADT • Unsorted List • Sequential Search • Selection Sort • Sorted List • Binary Search.
Data Structures(I) Circular Linked Lists Circular linked list A list in which every node has a successor; the last element is succeeded by the first element.
Data Structures Using C++
Computer Science and Software Engineering University of Wisconsin - Platteville 5. LinkedList Yan Shi CS/SE 2630 Lecture Notes.
M180: Data Structures & Algorithms in Java
Review Learn about linked lists
Chapter 3 ADT Unsorted List. List Definitions Linear relationship Each element except the first has a unique predecessor, and Each element except the.
C++ Plus Data Structures ADTs Unsorted List and Sorted List
Unsorted Lists CS 308 – Data Structures. What is a list? A list is a homogeneous collection of elements. Linear relationship between elements: (1) Each.
1 C++ Plus Data Structures Nell Dale Chapter 1 Software Engineering Principles.
CS Data Structures Chapter 8 Lists Mehmet H Gunes
Chapter 4 ADT Sorted List.
Implementing an Unsorted List as a Linked Structure CS 308 – Data Structures.
Variations of Linked Lists CS 302 – Data Structures Sections 6.2, 6.3 and 6.4.
1 expanded by J. Goetz Nell Dale Chapter 6 Lists Plus Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus C++ Plus Data Structures.
1 Nell Dale Chapter 3 ADTs Unsorted List and Sorted List Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus C++ Plus Data Structures.
5 Linked Structures. 2 Definition of Stack Logical (or ADT) level: A stack is an ordered group of homogeneous items (elements), in which the removal and.
1 Chapter 6 Lists Plus. ADT Sorted List Operations Transformers n MakeEmpty n InsertItem n DeleteItem Observers n IsFull n LengthIs n RetrieveItem Iterators.
1 Nell Dale Chapter 6 Lists Plus Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus C++ Plus Data Structures.
Doubly Linked Lists CS 308 – Data Structures. Node data info: the user's data next, back: the address of the next and previous node in the list.back.next.info.
C++ Programming: Program Design Including Data Structures, Fifth Edition Chapter 17: Linked Lists.
Dynamic Structures & Arrays.
1 Fall Chapter 4 ADT Sorted List. 2 Goals Describe the Abstract Data Type Sorted List from three perspectives Implement the following Sorted List.
Implementing a Sorted List as a Linked Structure CS 308 – Data Structures.
Data Structures Using C++ 2E
Chapter 4 ADT Sorted List.
1 Nell Dale Chapter 6 Lists Plus Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus C++ Plus Data Structures.
Chapter 3 ADT Unsorted List. Lecture 7 List Definitions Linear relationship Each element except the first has a unique predecessor, and Each element.
Chapter 7 More Lists. Chapter 7: More Lists 7.1 – Circular Linked Lists 7.2 – Doubly Linked Lists 7.3 – Linked Lists with Headers and Trailers 7.4 – A.
Linked List. List Definitions Linear relationship Each element except the first has a unique predecessor, and each element except the last has a unique.
Chapter 4 ADT Sorted List. 2 Goals Describe the Abstract Data Type Sorted List from three perspectives Implement the following Sorted List operations.
1 Chapter 16-1 Linked Structures Dale/Weems. 2 Chapter 16 Topics l Meaning of a Linked List l Meaning of a Dynamic Linked List l Traversal, Insertion.
Data Structures Using Java1 Chapter 4 Linked Lists.
3 ADT Unsorted List. List Definitions Linear relationship Each element except the first has a unique predecessor, and each element except the last has.
1 Chapter 16 Linked Structures Dale/Weems. 2 Chapter 16 Topics l Meaning of a Linked List l Meaning of a Dynamic Linked List l Traversal, Insertion and.
1 Chapter 13-1 Applied Arrays: Lists and Strings Dale/Weems.
Data Structures Using C++1 Chapter 5 Linked Lists.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 17: Linked Lists (part 2)
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 18: Linked Lists (part 2)
Chapter 6 Lists Plus. What is a Class Template? A class template allows the compiler to generate multiple versions of a class type by using type parameters.
1 C++ Plus Data Structures Nell Dale Chapter 5 Linked Structures Modified from the slides by Sylvia Sorkin, Community College of Baltimore County - Essex.
Chapter 4 ADT Sorted List. Sorted Type Class Interface Diagram SortedType class IsFull GetLength ResetList DeleteItem PutItem MakeEmpty GetItem Private.
What is a List? A list is a homogeneous collection of elements, with a linear relationship between elements. Each list element (except the first) has a.
1 Chapter 13-2 Applied Arrays: Lists and Strings Dale/Weems.
CS 302 – Data Structures Sections 3.1, 3.2, 3.4 & 3.5
1 Nell Dale Lecture 3 ADTs Unsorted List and Sorted List Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Modified by Reneta.
Data Structures Doubly and Circular Lists Lecture 07: Linked Lists
CSI 1340 Introduction to Computer Science II Chapter 3 ADTs Unsorted List and Sorted List.
1 What is a Circular Linked List? l A circular linked list is a list in which every node has a successor; the “last” element is succeeded by the “first”
Department of Computer Science 1 Some Practice Let’s practice for the final a little bit. OK?
1 Chapter 4 ADT Sorted List. 2 Sorted Type Class Interface Diagram SortedType class IsFull LengthIs ResetList DeleteItem InsertItem MakeEmpty RetrieveItem.
Chapter 17: Linked Lists. Objectives In this chapter, you will: – Learn about linked lists – Learn the basic properties of linked lists – Explore insertion.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 17: Linked Lists.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 18: Linked Lists.
1 Data Organization Example 1: Heap storage management Maintain a sequence of free chunks of memory Find an appropriate chunk when allocation is requested.
Chapter 16: Linked Lists.
C++ Programming:. Program Design Including
C++ Plus Data Structures ADTs Unsorted List and Sorted List
TA: Nouf Al-Harbi Data Structures LAB 3 TA: Nouf Al-Harbi
CS Data Structures Chapter 8 Lists Mehmet H Gunes
C++ Plus Data Structures
C++ Plus Data Structures
Chapter 4 Link Based Implementations
Unsorted Lists CS3240, L. Grewe.
Doubly Linked Lists Lecture 21 Tue, Mar 21, 2006.
Chapter 16 Linked Structures
CSI 1340 Introduction to Computer Science II
Data Structures and Algorithms Memory allocation and Dynamic Array
TA: Nouf Al-Harbi Data Structures LAB 2 TA: Nouf Al-Harbi
Presentation transcript:

Yan Shi CS/SE 2630 Lecture Notes 4. LinkedList Yan Shi CS/SE 2630 Lecture Notes

Linked List Unsorted List Sorted List Double linked list Circular linked list

Sorted and Unsorted Lists Elements are placed into the list in no particular order. SORTED LIST List elements are in an order that is sorted in some way -- either numerically or alphabetically by the elements themselves, or by a component of the element (called a KEY member) .

ADT Unsorted List Operations Transformers MakeEmpty PutItem DeleteItem Observers IsFull GetLength GetItem Iterators ResetList GetNextItem change state observe state process all

class UnsortedType<char> Private data: length 3 listData currentPos ? MakeEmpty ~UnsortedType ‘X’ ‘C’ ‘L’ GetItem PutItem DeleteItem . GetNextItem

Inserting ‘B’ into an Unsorted List Private data: length 3 listData currentPos ? ‘X’ ‘C’ ‘L’

location = new NodeType; item location ‘B’ Private data: length 3 listData currentPos ? ‘X’ ‘C’ ‘L’

location->info = item ; ‘B’ ‘B’ Private data: length 3 listData currentPos ? ‘X’ ‘C’ ‘L’

location->next = listData ; item location ‘B’ ‘B’ Private data: length 3 listData currentPos ? ‘X’ ‘C’ ‘L’

listData = location ; item ‘B’ location ‘B’ Private data: length 3 currentPos ? ‘X’ ‘C’ ‘L’

length++ ; item ‘B’ location Private data: length 4 listData currentPos ? ‘B’ ‘X’ ‘C’ ‘L’

Sorted Type Class Interface Diagram MakeEmpty Private data: length info [ 0 ] [ 1 ] [ 2 ] [MAX_ITEMS-1] currentPos IsFull GetLength GetItem InsertItem DeleteItem ResetList GetNextItem

InsertItem algorithm for Sorted Array Based List Find proper location for the new element in the sorted list. Create space for the new element by moving down all the list elements that will follow it. Put the new element in the list. Increment length.

DeleteItem algorithm for Sorted Array Based List Find the location of the element to be deleted from the sorted list. Eliminate space occupied by the item by moving up all the list elements that follow it. Decrement length.

class SortedType<char> Private data: length 3 listData currentPos ? MakeEmpty ~SortedType ‘C’ ‘L’ ‘X’ RetrieveItem InsertItem DeleteItem . GetNextItem 15

InsertItem algorithm for Sorted Linked List Find proper position for the new element in the sorted list using two pointers predLoc and location, where predLoc trails behind location. Obtain a node for insertion and place item in it. Insert the node by adjusting pointers. Increment length.

The Inchworm Effect

Inserting ‘S’ into a Sorted List predLoc location Private data: length 3 listData currentPos ? ‘C’ ‘L’ ‘X’ moreToSearch

Finding proper position for ‘S’ predLoc location NULL Private data: length 3 listData currentPos ? ‘C’ ‘L’ ‘X’ moreToSearch true

Finding proper position for ‘S’ predLoc location Private data: length 3 listData currentPos ? ‘C’ ‘L’ ‘X’ moreToSearch true

Finding Proper Position for ‘S’ predLoc location Private data: length 3 listData currentPos ? ‘C’ ‘L’ ‘X’ moreToSearch false

Inserting ‘S’ into Proper Position predLoc location Private data: length 4 listData currentPos ‘C’ ‘L’ ‘X’ ‘S’ moreToSearch false

What is a Circular Linked List? A circular linked list is a list in which every node has a successor; the “last” element is succeeded by the “first” element.

External Pointer to the Last Node

Why Circular Linked list? It doesn’t make any operation much shorter or simpler… It is useful for applications that require access to both ends of the list. What if the data to be added to the linked list is presorted?

What is a Doubly Linked List? A doubly linked list is a list in which each node is linked to both its successor and its predecessor.

Linking the New Node into the List

Deleting from a Doubly Linked List

What are Header and Trailer Nodes? A Header Node is a node at the beginning of a list that contains a key value smaller than any possible key. A Trailer Node is a node at the end of a list that contains a key larger than any possible key. Both header and trailer are placeholding nodes used to simplify list processing: we never have to handle special cases when inserting/deleting the first/end node.

A Sorted list Stored in an Array of Nodes

An Array with Linked List of Values and Free Space