Download presentation
Presentation is loading. Please wait.
1
CS 280 Data Structures Professor John Peterson
2
Merge Sorting Questions?
3
Exercises We’ll do these on the board in pairs. Sum a list of integers: int sumLI(LI l) Search a list of integers for a given value: boolean searchLI(int v, LI l) As above, except return the position: whereLI – use “-1” as the magic cookie for “not found”. int whereLI(int v, LI l); Compare two lists of integers: boolean equalsLI(LI 1, LI 2) Append two lists, destructive: LI appendLId(LI x, LI y) Append two lists, non-destuctive: LI appendLI(LI x, LI y)
4
Exercises We’ll do these on the board in pairs. Same Length Starts
5
Returning Two Values We’ll be creating functions that return more than one value. We could create a custom “pairing” class that is specific to the classes we need to return, but there’s a better way. How can we use a class to return a pair? How can we make this generic?
6
Generic Pairs We’re going to need a new Generic function class: public class Pair { public T first; public S second; public Pair(T first, S second) { this.first = first; this.second = second; }}
7
Exercise With Pairs Odd / Even iterative Odd / Even recursive Odd / Even destructive
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.