Fundamentals of Computer Science II (CSC-152 98S)

[Instructions] [Search] [Current] [Changes] [Syllabus] [Handouts] [Outlines] [Labs] [Assignments] [Examples] [Bailey Docs] [SamR Docs] [Tutorial] [API]


Lab 10: Lists, Sorting, and Debugging

Citation. This lab is based, in part, on Chapter 7 of Designing Pascal Solutions: Case Studies with Data Structures by Michael J. Clancy and Marcia C. Linn. Computer Science Press (W.H. Freeman), 1996.

Introduction. Henry and Heloise Hacker have been following along in the course notes for this course so that they can learn Java. As part of their normal jobs, they need to write a program that sorts some data stored in a file, with one record per line.

After some reflection, they decide that lists and quicksort are the way to go. That is, they implement lists (using singly-linked nodes) and then add a quicksort routine that works with lists rather than arrays.

Unfortunately, their program seems to crash randomly. I'm too busy to help them, so I've asked you to do so in my stead.

Description. In this laboratory, you will be attempting to debug code for a quicksort routine and corresponding list implementation.

Purpose. In this lab, you will strengthen your knowledge of list representations and of quicksort. You will also gain some experience debugging and think about techniques for debugging.

Files.

Narrative

Henry and Heloise have come to you for help in debugging their nonoperational program. They say "We know that you Grinnell students are quite smart, so we expect that you'll quickly discover our problems." As a generous person, you of course agree to help.

Most of us are overly enthusiastic, and want to run the program first. Compile the various components, built a small file to sort, and run
% ji LineSorter yourfile
What seems to go wrong? If nothing seems to go wrong, try some other inputs or ask your colleagues.

Now that you know that it doesn't work, you look at the code to find potential trouble spots. Can you identify any?

Having worked in my class, you know that it's essential to build a tester for each data structure you develop. Having followed along in the class notes, Henry and Heloise have built a tester for their class. Using the tester, verify that the various routines work.

You may observe that they haven't included a mechanism for testing sorting. Add appropriate code for testing the sorting routine.

If you try to test the sorting routine using the tester, you will observe that the sorting routine still fails. Now we're at the hard part. Why does it fail?

One strategy for determining what's wrong is to report on the status of the program (primarily the sorting routine) at various points. For example, you might want to print out the pivot and the three parts after partitioning. While inserting println statements is one way to go, you'll need to spend some time inserting them now, removing them when it seems to work, and then reinserting them later. Some languages provide debuggers that help with this work. Unfortunately, our implementation of Java does not include a particularly useful debugger.

As a substitute, I've provided a class, rebelsky.util.Reporter that simplifies reporting. It provides one constructor and three methods that you may want to use:

Insert appropriate reporting commands into the program. At minimum, you may want to print the pivot and the sublists at each stage of quicksort.

Does this help you find any trouble spots? It is likely that you'll observe something going wrong. It is now your responsibility to determine what is going wrong. How should you do this? Run the program by hand. That is, draw pictures that indicate the nodes, variables, and references, and trace what happens. It is likely that this will lead you to the error.

Fix any errors you find, and continue.


[Instructions] [Search] [Current] [Changes] [Syllabus] [Handouts] [Outlines] [Labs] [Assignments] [Examples] [Bailey Docs] [SamR Docs] [Tutorial] [API]

Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.

Source text last modified Tue Mar 10 09:39:34 1998.

This page generated on Tue Mar 10 09:42:43 1998 by SiteWeaver.

Contact our webmaster at rebelsky@math.grin.edu