Roger L. Kraft

CS 50200 - (Optional) Programming Assignment 7

This is an optional programming assignment. You can do it for extra credit (equivalent to one programming assignment).

This assignment makes use of the files contained in this zip file. This assignment is due Friday, May 9 (and no late assignments will be accepted).

This assignment is based on Generic_sorting_in_Scheme_vs_Java7_vs_Java8.zip.

You can do this assignment in Scheme and/or Java 7 and/or Java 8.

The idea of this assignment is roughly this. Given a list of triples of positive integers, like this,

     (5 8 3)
     (5 8 3)
     (8 6 7)
     (6 1 1)
     (1 10 6)
     (4 3 1)
     (8 4 6)
     (7 10 3)
     (8 10 3)
     (4 1 5)

write code that sorts the list in each of the following ways.

  1. Sort the list in ascending order based on the sum of the first two elements of each triple.
  2. Sort the list in descending order based on the sum of the first two elements of each triple.
  3. Sort the list in ascending order based on the sum of the first and third elements of each triple.
  4. Sort the list in ascending order based on the maximum of the second and third elements of each triple.
  5. Sort the list in descending order based on the maximum of the second and third elements of each triple.
  6. Sort the list in ascending order based on the maximum of the first and second elements of each triple.
  7. Sort the list in ascending order based on the first element of each triple, and use the second element of a triple as a tie breaker.
  8. Sort the list in descending order based on the third element of each triple, and use the first element of a triple as a tie breaker.
  9. Sort the list in ascending order based on the first element of each triple, and use the second element of a triple, in descending order, as a tie breaker.
  10. Sort the list in ascending order based on the sum of the first two elements of each triple, and use the first element of a triple as a tie breaker.

The real goal of the assignment is to implement these sorts in as little code as possible, hopefully by using carefully parameterized comparators. There are purposely a large number of sorts to try to force you to emphasize code reuse (one obvious way to do this problem is to write ten different comparators, one for each sorting problem, but that will lead to lots of redundant code).

You do not need to write the sorting function. For Java, use the Collections.sort() method, as we did in the examples from class. For Scheme, use the insertion sort function that we wrote in class.

In the zip file there is some code to help you get started. There is a Scheme file, triples.rkt, that contains the sort function from class and a function that generates lists of random triples (for testing). If you want to use Scheme, put your solutions in that file.

There is a Java file, Triples.java, that contains a static method to generate lists of random triples. The file also contains a main() method that you can use to test your code. If you want to use Java, put your solutions in that file (if you want to use Java 7 and Java 8, make an extra copy of the file, one for each version of Java).

Turn in any combination of sorts that you want. If you want to do only a few of the sorting problems, but do them in all three languages, that is fine. If you want to do all of the sorting problems, but do them in only one language, that's fine too. And if you want to do all of the sorting problems in all three languages, than that's great. But if you do only a couple of sorting problems in only one language, then that won't be worth much credit.

Turn in a zip file called CS502Hw7Surname.zip (where Surname is your last name) containing your code that does the sorting. Include a text file that briefly explains what you did (which languages did you use, how many of the sorting problems did you implement, roughly how many lines of code did it take in each language, what techniques did you use to promote code reuse).

This (optional) assignment is due Friday, May 9 (and no late assignments will be accepted).