©2010 Felleisen, Proulx, et. al.

8  Loops; Sorting

Goals

In the first part of the lab you will learn how to convert recursive loops to imperative (mutating) loops using either the Java while statement or the Java for statement to implement the imperative loops.

In the second part we will look at how we can leverage the direct access to the items within the data set to implement a new kind of sorting algorithm.

For this lab download the files in Lab9-Sp2010.zip. The folder contains the following files:

Create a new Project Lab9 and import into it all files from the zip file. Import the tester.jar and colors.jar.

8.1  Converting Recursive Loops into Imperative while Loops

The goal of this part of the lab is to make sure you know how to implement a traversal over data within an ArrayList using Java while and for loops. Make sure you understand the role of each part of the loop method definition: BASE VALUE, CONTINUATION-PREDICATE, CURRENT, ADVANCE, UPDATE, and know how to construct both the while loop and the for loop.

Last modified: Friday, May 28th, 2010 7:39:15am