Download presentation
Presentation is loading. Please wait.
1
Sorted Lists and Their Implementations
CS Data Structures Mehmet H Gunes Modified from authors’ slides
2
Contents Specifying the ADT Sorted List Link-Based Implementation
Implementations That Use the ADT List Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
3
Specifying the ADT Sorted List
The ADT sorted list maintains its entries in sorted order. It is a container of items that determines and maintains order of entries by their values. Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
4
Specifying the ADT Sorted List
Test whether sorted list is empty. Get number of entries in sorted list. Insert entry into a sorted list. Remove given entry sorted list. Remove entry at given position. Remove all entries. Look at (get) th entry at a given position Get position of a given entry. Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
5
Specifying the ADT Sorted List
UML diagram for the ADT sorted list Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
6
Specifying the ADT Sorted List
View C++ interface in Listing 12-1 Formalizes initial specifications of ADT sorted list ADT sorted list can add, remove, or locate entry, given entry as argument Sorted list will not allow add or replacement of entry by position Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
7
A Link-Based Implementation
View header file for linkSortedList, Listing 12-2 Begin Implementation: Copy Constructor Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
8
A Link-Based Implementation
Method copyChain Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
9
A Link-Based Implementation
Places to insert strings into a sorted chain of linked nodes Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
10
A Link-Based Implementation
Method insertSorted Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
11
A Link-Based Implementation
Private method getNodeBefore Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
12
Implementations That Use the ADT List
Containment Public inheritance Private inheritance Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
13
Containment An instance of a sorted list that contains a list of its entries Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
14
Containment View header file source code, Listing 12-3
SortedListHasA is composed of an instance of the class LinkedList View header file source code, Listing 12-3 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
15
Containment Constructors
Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
16
Containment Destructor Method insertSorted
Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
17
Containment Methods isEmpty , getLength , remove, clear , and getEntry of ADT sorted list has same specifications as in ADT list Example, method remove Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
18
Efficiency Issues The worst-case efficiencies of ADT list operations for array-based and linkbased implementations Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
19
Efficiency Issues The worst-case efficiencies of the ADT sorted list operations when implemented using an instance of the ADT list Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
20
Public Inheritance SortedListIsA as a descendant of LinkedList
Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
21
Public Inheritance View header file, Listing 12-4
Implementation – constructors, destructor Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
22
Public Inheritance Method insertedSorted
Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
23
Public Inheritance Method removeSorted
Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
24
Public Inheritance Method getPosition
Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
25
Public Inheritance Overridden method insert
Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
26
Private Inheritance View header file for SortedListAsA, Listing 12-5
Implementation Method getEntry Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
27
Private Inheritance The SortedListAsA class implemented in terms of the LinkedList class Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.