Question: I'm getting a warning for a portion of code. While I've been looking around for a better explanation, I was wondering if anyone could maybe

I'm getting a warning for a portion of code. While I've been looking around for a better explanation, I was wondering if anyone could maybe shine some light on it for me.

/**

* Performs a linear search on a data set of integers given a key value to

* search for. Look in SearchingSorting slides for implementation.

*

* Type Parameters:

* E - Generic type found in the passed ArrayList.

*

* @param data - Set of data to search.

* @param key - Value to search for.

* @return If the key is found in data, returns the index of the key,

* if not found returns -1.

*/

public static int linearSearch(List data, E key)

{

int size = data.size();

for (int i = 0; i < data.size(); i++)

{

int min_index = i;

for(int j = i + 1; j < data.size(); j++)

{

if(data.get(j).compareTo(data.get(min_index)) < 0) <-- I'm getting a warning with this .compareTo (The method compareTo(E) is undefined for the type E)

{

min_index = j;

}

}

return -1; //not found

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!