The goal for this exercise is to create a method that will do a linear search of an array, which should be fairly easy. A secondary goal include the introduction of a pattern that consists of you creating a ‘Find’ method, then try it out.
What you need to do to prepare for this exercise:
For this exercise, you should implement the FindIntegerLinear
method in the SearchingAndSorting
class. This is located
in the starter solution in the Student_Answers.cs
file. The method should have two parameters:
an int
to search for, and an array of int
s to search within. The function should return a bool
value: true
if
the number to search for is contained in the array, false
if it isn't. You must do the search using a LINEAR
searching, meaning that you use a simple for loop, and check each element one by one until you find the element
you're looking for (or find that the target isn't in the array). The FindIntegerLinear
method should be implemented
in the SearchingAndSorting
class.
Once you’ve done that, you should test the function (once you've written it). You’ll need to do this by adding code to main which searches through various arrays (which you’ll also need to create)
Implement and the FindIntegerLinear
method, as described above.