Algorithms and OOD (CSC 207 2014S) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Rubric] - [Calendar]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Java 7 API] [Java Code Conventions] [GNU Code Conventions]
Related Courses: [CSC 152 2006S (Rebelsky)] [CSC 207 2013F (Rebelsky)] [CSC 207 2013S (Walker)] [CSC 207 2011S (Weinman)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker (Course)] [Issue Tracker (Textbook)]
Overview
Let's write a signature
public AN ARRAY sort(AN ARRAY, THE THING THAT DOES THE COMPARISONS)
Design issues:
Let's make that look more like Java
public int[] sort(int[] vals, Comparator<Integer> order)
Using this model
sort(grades, new Comparator<Integer>()
{
public int compare(Integer x, Integer y)
{
return x-y; // Hack. Dangerous
}
} // Comparator<Integer>
);
Whoops. Might overflow.
Let's generalize
public static <T> T[] sort(T[] vals, Comparator<T> order)
Perhaps sort should be a mutator of the array class.
public class JavaArray
{
public void sort(Comparator<T> order)
} // class JavaArray
Object-oriented strategy: Make objects that know how to sort
public interface Sorter
Do we also have sorting routines for things with a natural order, such as BigIntegers or Strings.
public T[] pureSort(Comparable<T>[] vals) // Approximate syntax
Another design decision: Is the sorting algorithm "stable"?
Four algorithms to study
Unit tests for sorting algorithms
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Rubric] - [Calendar]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Java 7 API] [Java Code Conventions] [GNU Code Conventions]
Related Courses: [CSC 152 2006S (Rebelsky)] [CSC 207 2013F (Rebelsky)] [CSC 207 2013S (Walker)] [CSC 207 2011S (Weinman)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker (Course)] [Issue Tracker (Textbook)]
Copyright (c) 2013-14 Samuel A. Rebelsky.

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.