Presentation is loading. Please wait.

Presentation is loading. Please wait.

© 2016 Pearson Education, Ltd. All rights reserved.

Similar presentations


Presentation on theme: "© 2016 Pearson Education, Ltd. All rights reserved."— Presentation transcript:

1 © 2016 Pearson Education, Ltd. All rights reserved.
Sorted Lists Chapter 16 Data Structures and Abstractions with Java, 4e, Global Edition Frank Carrano © 2016 Pearson Education, Ltd.  All rights reserved.

2 © 2016 Pearson Education, Ltd. All rights reserved.
List Entries in a list are ordered simply by positions within list Can add a sort operation to the ADT list Add an entry to, remove an entry from sorted list Provide only the entry. No specification where entry belongs or exists © 2016 Pearson Education, Ltd.  All rights reserved.

3 Specifications for ADT Sorted List
DATA A collection of objects in sorted order and having the same data type The number of objects in the collection Operations add(newEntry) remove(anEntry) getPosition(anEntry) © 2016 Pearson Education, Ltd.  All rights reserved.

4 Specifications for ADT Sorted List
Additional Operations -- behave as they do for the ADT list getEntry(givenPosition) contains(anEntry) remove(givenPosition) clear() getLength() isEmpty() toArray() © 2016 Pearson Education, Ltd.  All rights reserved.

5 Specifications for ADT Sorted List
LISTING 16-1 The interface SortedListInterface © 2016 Pearson Education, Ltd.  All rights reserved.

6 Specifications for ADT Sorted List
LISTING 16-1 The interface SortedListInterface © 2016 Pearson Education, Ltd.  All rights reserved.

7 Linked Implementation
LISTING 16-2 An outline of a linked implementation of the ADT sorted list © 2016 Pearson Education, Ltd.  All rights reserved.

8 Linked Implementation
FIGURE 16-1 Places to insert names into a sorted chain of linked nodes © 2016 Pearson Education, Ltd.  All rights reserved.

9 Linked Implementation
Algorithm for add routine. © 2016 Pearson Education, Ltd.  All rights reserved.

10 Linked Implementation
An iterative implementation of add © 2016 Pearson Education, Ltd.  All rights reserved.

11 Linked Implementation
The private method getNodeBefore © 2016 Pearson Education, Ltd.  All rights reserved.

12 Linked Implementation
FIGURE 16-2 Recursively adding Luke to a sorted chain of names © 2016 Pearson Education, Ltd.  All rights reserved.

13 Linked Implementation
FIGURE 16-2 Recursively adding Luke to a sorted chain of names © 2016 Pearson Education, Ltd.  All rights reserved.

14 Linked Implementation
A recursive implementation of add © 2016 Pearson Education, Ltd.  All rights reserved.

15 Linked Implementation
A recursive implementation of add © 2016 Pearson Education, Ltd.  All rights reserved.

16 Linked Implementation
FIGURE 16-3 Recursively adding a node at the beginning of a chain © 2016 Pearson Education, Ltd.  All rights reserved.

17 Linked Implementation
FIGURE 16-4 Recursively adding a node between existing nodes in a chain © 2016 Pearson Education, Ltd.  All rights reserved.

18 Linked Implementation
FIGURE 16-4 Recursively adding a node between existing nodes in a chain © 2016 Pearson Education, Ltd.  All rights reserved.

19 Linked Implementation
FIGURE 16-4 Recursively adding a node between existing nodes in a chain © 2016 Pearson Education, Ltd.  All rights reserved.

20 Efficiency of the Linked Implementation
FIGURE 16-5 The worst-case efficiencies of the operations on the ADT sorted list for two implementations © 2016 Pearson Education, Ltd.  All rights reserved.

21 Implementation That Uses the ADT List
FIGURE 16-6 An instance of a sorted list that contains a list of its entries © 2016 Pearson Education, Ltd.  All rights reserved.

22 Implementation That Uses the ADT List
Our class SortedList will implement the interface SortedListInterface © 2016 Pearson Education, Ltd.  All rights reserved.

23 Implementation That Uses the ADT List
The method add. © 2016 Pearson Education, Ltd.  All rights reserved.

24 Implementation That Uses the ADT List
The method remove. © 2016 Pearson Education, Ltd.  All rights reserved.

25 Implementation That Uses the ADT List
FIGURE 16-7 A sorted list in which Jamie belongs after Carlos but before Sarah © 2016 Pearson Education, Ltd.  All rights reserved.

26 Implementation That Uses the ADT List
The implementation of getPosition © 2016 Pearson Education, Ltd.  All rights reserved.

27 Implementation That Uses the ADT List
FIGURE 16-8 The worst-case efficiencies of selected ADT list operations for array-based and linked implementations © 2016 Pearson Education, Ltd.  All rights reserved.

28 Implementation That Uses the ADT List
FIGURE 16-9 The worst-case efficiencies of the ADT sorted list operations when implemented using an instance of the ADT list © 2016 Pearson Education, Ltd.  All rights reserved.

29 © 2016 Pearson Education, Ltd. All rights reserved.
End Chapter 16 © 2016 Pearson Education, Ltd.  All rights reserved.


Download ppt "© 2016 Pearson Education, Ltd. All rights reserved."

Similar presentations


Ads by Google