/************************************************************************

			   Linear Search

	<put your name, DCS login name & student number here>

			WHAT YOU HAVE TO DO

	Fill in the code in the method "search" below
	so that it returns the "position" in the "array"
	where the value "seek" occurs (if it does).

	Don't think YET about the case where it doesn't occur.

	These instructions continue further down the file ...

***********************************************************************/

// DO NOT CHANGE the "class" line

// (except perhaps to change "Linear" into "Linear2" etc. if
// you want to write another version in the file Linear2.java
// ("implements Searching" tells the Tester what problem you're doing.))
 
public class Linear implements Searching {


    // Here is the one method that you have to write.
    // Do not change the method declaration 
    // (yes, it must be "public" and NOT "static").

    public int search (int[] array, int seek) {
	int size = array.length;


	// A logical formula
	// (the "precondition" of the method)
	// belongs here.
	// This will be discussed in the next lecture:
	// please just leave the comments about logic
	// here as they are,   and add the logical
	// formulae during or after the lecture.


	// You ONLY need to declare this one local variable.
	int position;


	// Another logical formula
	// (the "precondition" of the loop)
	// belongs here.


	// Please use "while", NOT "for", in this course.
	// (The thing that you write in brackets
	// will be called the "loop test" in this course.)
	while (     ) {


	    // Yet another logical formula
	    // (the "loop invariant")
	    // belongs here.


	    // Write your code (the "body" of the loop) here.

	}

	// The fourth and final logical formula
	// (the "postcondition" of the loop and of the method)
	// belongs here.


	// Here we say where "seek" occurs in the array
	// and go home.
	return position;
    }


    // PLEASE IGNORE THESE LINES - DO NOT CHANGE THEM
    public static int choice = 0;
    public void choice (int c) { choice=c; }
    public boolean sorted_data () { return false; }
}

/************************************************************************
When you have written your code,  do
	run Linear.java
This will compile your code for you (no need to use "javac")
and run it on a random array of length 20.

Do this several times.

You can make the Tester call your method with a longer or
shorter array, or one that is sorted (ascending), reverse sorted
(descending) or strictly sorted by addition combinations of words like
	run Linear.java size=10 strictly reverse sorted
to the command.

Alternatively, you can tell it exactly what array to use:
	run Linear.java array=2,4,6,8,0,9,7,5,3,1 seek=5
(beware that there must be NO SPACES in the listing).

Answer the following questions IN THIS FILE:

In the situation where "seek" occurs TWICE OR MORE OFTEN in the array,
which "position" of the two or more occurrences does your method indicate?

<insert your answer here>

What "position" does your method return if "seek" is NOT in the array?
In what way does this number depend on the size of the array?

<insert your answer here>

Why is this an APPROPRIATE result for the method to return in this case?

<insert your answer here>

What other result value might you choose to return in this case instead?
Give a reason.

<insert your answer here>

How would you change the code to make it return this alternative result?

<insert your changed code here, NOT above>

Now do this:
	check Linear.java

<insert what the Tester reports here>

Does the Tester confirm what you observed about the cases where "seek"
is either absent or occurs more than once in the array?

Assuming that you have written your code in the very simple way that
was intended,  you should find that its behaviour can be described
MORE PRECISELY than what you were originally asked to do, or expected
yourself than it would do.

<in what way is it more precise?>

When your code is correct and you have finished your answers
to these questions,  print out this file (including your answers)
by doing
	a2ps -Pitlevel1 Linear.java
or
	enscript -Pitlevel1 Linear.java

Show your printout to the teaching assistant, and bring it to the next
lecture,  so that you can write in the logical formulae mentioned above.

Now look at the file "RLinear.java".

***********************************************************************/
