Algorithms and OOD (CSC 207 2013F) : EBoards

CSC207.01 2013F, Class 30: An Introduction to Sorting


Overview

Admin

HW 7

How do we deal with predicates in search/select

From the exam ...

 public interface Predicate<T> {
      public boolean test(T val);
 }

So, for testing ...

 public class IsEven implements Predicate<Integer> {
      public boolean test(Integer val) {
          return (val % 2) == 0;
      }
 }

Can we make doubly- circularly-linked lists? Yes.

Notes on Exam 1

Was Sam overly harsh on HW6?

The problem of sorting

An object-oriented approach

Signature for the sort method?

/**
 * Sort an array in place, using comp to arrange values.
 *
 * @pre
 *   We can safely apply comp to any pair of elements in unsorted.
 *   A.k.a "For all, i, j, 0 <= i, j < unsorted.length,
 *     comp(unsorted[i],unsorted[j]) does not throw an exception.
 * @post
 *   For all reasonable i, comp.compare(unsorted[i],unsorted[i+1) <= 0
 *   unsorted is a permutation of the original unsorted
 */
public void sort(T[] unsorted, Comparator<T> comp);

How do we 'package' it up (not put it in a Java package)?

Testing our sorting algorithm

Copyright (c) 2013 Samuel A. Rebelsky.

Creative Commons License

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.