Ben’s Lecture Cliff Notes

Slides:



Advertisements
Similar presentations
Comparable and Comparator Interfaces Ben Rodes. Disclaimer.
Advertisements

Problem Solving 5 Using Java API for Searching and Sorting Applications ICS-201 Introduction to Computing II Semester 071.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Discrete Math CSC151 Analysis of Algorithms. Complexity of Algorithms  In CS it's important to be able to predict how many resources an algorithm will.
Recursion Chapter 7. Chapter 7: Recursion2 Chapter Objectives To understand how to think recursively To learn how to trace a recursive method To learn.
Selection Sort
Computer Science 209 The Strategy Pattern I: Comparisons and Layouts.
12.1 Introduction Checklists are used as a technique to give status information in a formalized manner about all aspects of the test process. This chapter.
Information Integration By Neel Bavishi. Mediator Introduction A mediator supports a virtual view or collection of views that integrates several sources.
Selection Sort
Bubble Sort Example
CS 350 – Software Design The Adapter Pattern – Chapter 7 Gang of Four Definition: Convert the interface of a class into another interface that the client.
CompSci 100 Prog Design and Analysis II Sept 14, 2010 Prof. Rodger CompSci 100, Fall
JavaScript: API’s, Parameters and Creating Functions with Parameters
Understanding Shape, Center, and Spread
How to Make a Dichotomous Key
Recursion Topic 5.
INTRODUCTION TO PROBLEM SOLVING
Chapter 9 Polymorphism.
15.1 – Introduction to physical-Query-plan operators
Entry Ticket: Algorithms and Program Construction
Patent Mapping and Visualization
CIS 200 Test 01 Review.
Interface Java 7 COMP T1.
Factors and Primes.
Chapter 19 Java Data Structures
CMPT 120 Topic: Functions – Part 4
Presented by: Kai Zhu Professor: Dr. T.Y. Lin Class ID: 220
Understanding Agent Knowledge through Conversation
Interfaces I once attended a Java user group meeting where James Gosling (Java's inventor) was the featured speaker. During the memorable Q&A session,
Java Programming: From Problem Analysis to Program Design,
What is a mineral? How are minerals identified? How do minerals form?
Computational Thinking
ECET 370 HELPS Education Your Life-- ecet370helps.com.
Topic 7 Interfaces I once attended a Java user group meeting where James Gosling (one of Java's creators) was the featured speaker. During the memorable.
Lecture 6 Project review
Collections class Method name Description binarySearch(list, value)
Teacher Functions.
Evaluate nth Roots and Use Rational Exponents
Afsheen Khosravian George Moomau Gibran Ali Ryan Workman Sina Iman
Median Finding and Quick Sort
PC02 Term 2 Test Recursion and Sorting. PC02 Term 2 Test Recursion and Sorting.
Programming in C# Comparison (Sorting)
Database Systems Chapter 1
Bertil Muth, ProSTEP iViP association
The facts or numbers that describe the results of an experiment.
Unit 6: Application Development
Inference for Proportions
Lesson 12 – Social Skill: Making a Complaint.
Software Requirements Specification Document
Chapter 8 Collection Types.
Open on the student drive
Bertil Muth, ProSTEP iViP association
Review and Prepare for Test 2
Bubble Sort Example 9, 6, 2, 12, 11, 9, 3, 7 6, 9, 2, 12, 11, 9, 3, 7 Bubblesort compares the numbers in pairs from left to right exchanging.
The facts or numbers that describe the results of an experiment.
Computer Science The 6 Programming Steps.
LTSS Lesson 6 Getting Sorted
CSE 373 Data Structures and Algorithms
CS2013 Lecture 7 John Hurley Cal State LA.
Entry Guideline Template
Day 5: Character Quote Analysis & Kite Design
Today we will: analyze characteristics of relationships
CMPE212 – Reminders Assignment 2 due next Friday.
CMPT 120 Lecture 19 – Unit 3 – Graphics and Animation
Lecture 20 – Practice Exercises 4
CSE 373: Data Structures and Algorithms
CMPT 120 Lecture 26 – Unit 5 – Internet and Big Data
Phase 1: Concept Development Identify Customer Needs - Interpret
Presentation transcript:

Ben’s Lecture Cliff Notes

Generic Functions I want to write generic functions, so I don’t have to rewrite them again. The problem is functions often depend on functionality provided by the parameters. How can I write a generic function, using generic parameters, yet those parameters are mandated to have certain functionality? Answer: Interfaces (a contract of functionality) Required methods, but the definition is up to the user.

A Generic Sort To write a generic sort, I need to be able to compare the objects I am asked to sort. Each object must have a function to compare itself with another object. Solution: The sort function accepts a collection of objects that implement the Comparable interface Comparable objects have a compareTo function. Now I can sort any collection so long as the objects implement this interface, using one sort function. Call compareTo for each object in the collection.

Problem The Comparable interface only provides one way to compare. What if I need diverse mechanisms of comparison? (sort by size, shape, color, ….) How do I write a generic sort algorithm that can sort the objects by comparing any characteristic? Answer: Provide the sort a Comparator in addition to the collection

Comparator The Comparator interface contains one method, compare. The sort function can then use any object that implements the Comparator interface to perform the comparisons desired, and then the sort can sort accordingly. Sort accepts the collection and the comparator.