mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-21 19:14:55 +08:00
docs: update the whole repository
* fix some bugs * delete duplicate files * format code
This commit is contained in:
@ -7,17 +7,14 @@ import java.util.stream.Stream;
|
||||
* Linear search is the easiest search algorithm
|
||||
* It works with sorted and unsorted arrays (an binary search works only with sorted array)
|
||||
* This algorithm just compares all elements of an array to find a value
|
||||
*
|
||||
* <p>
|
||||
* Worst-case performance O(n)
|
||||
* Best-case performance O(1)
|
||||
* Average performance O(n)
|
||||
* Worst-case space complexity
|
||||
*
|
||||
*
|
||||
* @author Varun Upadhyay (https://github.com/varunu28)
|
||||
* @author Podshivalov Nikita (https://github.com/nikitap492)
|
||||
*
|
||||
*
|
||||
* @see BinarySearch
|
||||
* @see SearchAlgorithm
|
||||
*/
|
||||
@ -33,7 +30,7 @@ public class LinearSearch implements SearchAlgorithm {
|
||||
*/
|
||||
@Override
|
||||
public <T extends Comparable<T>> int find(T[] array, T value) {
|
||||
for (int i = 0; i < array.length ; i++) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
if (array[i].compareTo(value) == 0) {
|
||||
return i;
|
||||
}
|
||||
|
Reference in New Issue
Block a user