CSC161 2011S Imperative Problem Solving

Laboratory: Lists

Summary:

Prerequisites: Familiarity with pointers, linked lists, malloc, and more.

Preparation

a. Create a new directory for this lab. I would suggest something like CSC161/Labs/Lists.

b. Make a copy of Examples/Lists/lists.tar.

c. Unpack that tarball in your directory.

d. Review the list.h file to make sure you understand which functions the list library should provide.

e. Review the implementations of list_get (provided) and list_index_of (written in class).

Exercises

Exercise 1: Setting Elements

An important list operation is list_set(lst, n, val), which sets the nth element of lst to val.

a. Review the documentation for list_set so that you know what it should do.

b. Write some simple unit tests for list_set. For example, you might create a four element list of the word "Bravo" set the second element to "Beta", and make sure that the second element is "Beta" but the rest remain "Bravo".

c. Write some simple experiments for list_set. You might create a four element list of the word "Bravo" and set the second element ot "Beta"

d. Implement list_set.

Exercise 2: Inserting Elements

a. Review the documentation for list_insert so that you know what it should do.

b. Write some simple unit tests for list_insert.

c. Write some simple experiments for list_insert.

d. Implement list_insert.

Exercise 3: Deleting Elements

a. Review the documentation for list_delete so that you know what it should do.

b. Review the implementation of list_cut so that you are comfortable with the strategy for removing elements from a list.

c. Write some simple unit tests for list_delete.

d. Write some simple experiments for list_delete.

e. Implement list_delete.

Exercise 4: Deleting Elements, Revisited

There are two common strategies for implementing list_delete. One might delete a element by finding its index and using list_cut. One might delete an element by iterating through the list until one finds the element.

Pick whichever of these stratedy you did not use for the previous exercise and implement list_delete using that strategy.

 

History

Wednesday, 27 April 2011 [Samuel A. Rebelsky]

  • Wrote problem in rough draft form (in outline).

Thursday, 28 April 2011 [Samuel A. Rebelsky]

 

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 Thu Apr 28 23:17:16 2011.
The source to the document was last modified on Thu Apr 28 23:17:10 2011.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CSC161/2011S/Labs/lists-lab.html.
A PDF version of this document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CSC161/2011S/Labs/lists-lab

Samuel A. Rebelsky, rebelsky@grinnell.edu

Copyright © 2010 Samuel A. Rebelsky. This work is licensed under a Creative Commons Attribution-NonCommercial 2.5 License. To view a copy of this license, visit or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.