CS 214 Project 11: Searching a List


When dealing with list-related problems, it is frequently necessary to search a list for a given value. This week's exercise is to write a subprogram to perform this operation, in each of our four languages.

Your operation should satisify the following specification:

   Receive: aList, a list of integers; and
            aValue, an integer.
   Return: the position of aValue within aList, if aValue is present in aList;
           -1, otherwise.
This is an exercise to practice the use of each of our languages: your subprogram must traverse the list in order to solve the problem (as opposed to using any predefined search capabilities provided by our languages).

Testing. Show that your subprogram works correctly by using it to find the position of the integer 99 in list1, list2 and list3. Create a fourth list list4 in which 99 is not present, and show the result of using your subprogram to search that list.

Turn in. Using an approach like what we did in the lab, make a single script file named proj11-results, in which you list each program, show that it builds without any syntax errors or warnings, and show some executions that demonstrate its correctness. Then submit your project by copying that single file into your personal folder in /home/cs/214/current/:

   cp proj11-results /home/cs/214/current/yourUserName
replacing yourUserName with your login name. The grader will access and grade your project results from there, using the criteria from this grade sheet.


Calvin > CS > 214 > Projects > 11


This page maintained by Joel Adams.