Upload
roxanne-scott
View
232
Download
0
Tags:
Embed Size (px)
Citation preview
Ordered Lists and Sorted Lists
Chapter 7
Ordered Lists• Array version vs. Linked-list version
List, Ordered List and Sorted List Hierarchy
Searchable Container Operations• Insert: put objects into the container
• Withdraw: remove objects from the container
• Find: locate objects in the container
• IsMember: test whether a given object instance is in the container
Ordered Lists• Additional operations:• FindPosition: find the position of an object in the
ordered list• Operator [ ]: access the object at a given position in the
ordered list• Withdraw( Position&): remove the object at a given
position from the ordered list• InsertAfter: insert an object into the ordered list after
the object at a given position• InsertBefore: Insert an object before the object at a
given position
List and Ordered List Class Definition
Array Implementation
Constructor, Insert(), and [ ]
IsMember() and Find()
Withdraw()
Pos Class
FindPosition() and [ ]
Insert at Arbitrary Position
InsertAfter()
Withdraw an Item
Withdraw()
Linked List Implementation
Constructor, Insert() and [ ]
IsMember() and Find()
Withdraw()
Pos Class
FindPosition()
InsertAfter()
Withdraw()
Sorted Lists• Additional operations:
• FindPosition: find the position of an object in the sorted list
• Operator [ ]: access the object at a given position in the sorted list
• Withdraw: remove the object at a given position from the sorted list
SortedList Class Definition
Array Implementation
Inserting Items in a Sorted List
Insert()
Binary Search
Finding Items
Withdraw()
Linked List Implementation
Insert()