Program Assignment - Searching: Linearly & Binary

Download the following files for the two program assignments:

  1. Place all the above cpp files in your project. lsmf.cpp is your dirver program for this problem. Write all your code in this file. Look in fish.h and randgen.h for details about their class behaviours. You will not have to work with any of the other classes, but they are needed for the project to compile!

    Linear Search with Move to Front (LSMF) works as follows: each time you search, move the fish that's found one step closer to the front of the vector. For example, suppose your vector contains the following:

    Fish: 6  4  2  5  1  7  3  10 9  8
    

    and you search for fish id #7. After you find it, you move it one step toward the front by exchanging it with fish id #1; so the vector will now look like this:

    Fish: 6  4  2  5  7  1  3  10 9  8
    

    The function returns the location of where the fish was moved too if found, otherwise it returns -1.

    Write the LSMF function that implements the above searching technique.

    Write the support functions in lsmf.cppto show that your linear serach function actually works.

  2. Fill a 1000 element vector with the even fish id # integers from 2 to 2000 You can use the same LoadVector funciton form the last problem (as well as the functions GetFish and DisplayVector.) Write the standard linear search and the binary search functions. For any given fish id output the following: For example:

    Enter fish ID to search for: 1000
    The linear search found fish 1000 at location 499 taking 500 searches to do so
    The binary search found fish 1000 at location 499 taking 1 searches to do so
    
    Enter fish ID to search for: 99
    The linear search did not find fish 99 after taking 1000 searches to do so
    The binary search did not find fish 99 after taking 10 searches to do so