Worksheet W.A.28.1
Name ________________________________
Given the following definitions and specifications, write a sequential search algorithm to search
an array for an item with a given id number.
class item
public int id;
public int inv;
item[] list;
* Will search for an idToSearch value. The array list is initialized
* with data from 0..list.length-1
public int sequentialSearch (item[] list, int idToSearch)
// Your code goes here
We will assume that values stored in the array have unique id fields but are unsorted. If the list
is empty or idToSearch does not exist in the list, a -1 value is to be returned; otherwise the
method returns the index position of idToSearch in the list. The solution should be efficient;
the method should immediately terminate if the answer is found.
You must also include a detailed precondition, action, and postcondition summary at the top of
the method. After coding an answer, modify the source code for the lab work and test your
sequential search algorithm.
1. Add the sequential search algorithm to the source code.
2. Disable the sorting routine after the text file is loaded from disk.
3. Test the same Id values as assigned for the binary search of file50.txt.
On the back of this sheet or on another piece of paper, your work should include the method and
the run output of the Id values to be searched.
Visual J# .NET Curriculum for APCS, Lesson 28
© ICT 2004,, All Rights Reserved
Use permitted only by licensees in accordance
with license terms (
W.A.28.1 (Page 1)