CSC161 2010F Imperative Problem Solving
[Skip to Body]
Primary:
[Front Door]
[Schedule]
-
[Academic Honesty]
[Instructions]
Current:
[Outline]
[EBoard]
-
[Assignment]
[Lab]
Groupings:
[EBoards]
[Assignments]
[Examples]
[Exams]
[Handouts]
[Labs]
[Outlines]
[Readings]
Related Courses:
[CSC195 2003S (Rebelsky)]
[CSC161 2009F (Coahran)]
[CSC161 2010S (Walker)]
Misc:
[SamR]
[ISO]
[GNU Coding Standards]
Back to Pointers to Functions. On to Pause for Breath.
This outline is also available in PDF.
Held: Wednesday, 10 November 2010
Summary: We continue our exploration of sorting.
Related Pages:
Notes:
Overview:
As you may recall, we developed a generic template for sorting algorithms.
TYPE
, the type of values that you're sorting;
PREFIX(FUN)
, a macro that puts a prefix on a function name; and
MAY_PRECEDE(X,Y)
, which the routine can use to determine
whether or not X may precede Y in the sorted version.
void PREFIX(sort)(TYPE values[], int size);
K&R take a slightly different perspective. They focus on arrays of pointers (most frequently arrays of strings) and pass in a comparator.
void sort(void *values[], int size, int (*compare)(void *x, void *y));
Is that enough to let us sort arrays of integers or doubles? No.
Can we combine the ideas? Certainly.
void PREFIX(sort)(TYPE values[], int size, int (*compare)(TYPE x, TYPE y));
Is this a good idea? I'll let you reflect on that question.
Weinman suggests an alternative way of combining the two. We skip the macro techinque and pass in the size of objects.
void sort(void *values, int size, int valsize, int (*compare)(void *x, void *y));
Is this a good idea? I'll also let you reflect on that question.
We've sketched out a variety of sorting algorithms.
There are also many more.
Suppose we have a library of correctly implemented sorting routines. How do we decide which one to use?
Back to Pointers to Functions. On to Pause for Breath.
[Skip to Body]
Primary:
[Front Door]
[Schedule]
-
[Academic Honesty]
[Instructions]
Current:
[Outline]
[EBoard]
-
[Assignment]
[Lab]
Groupings:
[EBoards]
[Assignments]
[Examples]
[Exams]
[Handouts]
[Labs]
[Outlines]
[Readings]
Related Courses:
[CSC195 2003S (Rebelsky)]
[CSC161 2009F (Coahran)]
[CSC161 2010S (Walker)]
Misc:
[SamR]
[ISO]
[GNU Coding Standards]
Disclaimer:
I usually create these pages on the fly
, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Wed Dec 8 10:57:11 2010.
The source to the document was last modified on Fri Aug 27 07:12:23 2010.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CSC161/2010F/Outlines/outline.40.html
.