document linear search

This commit is contained in:
Krishna Vedala 2020-05-28 20:41:31 -04:00
parent 2b57d1ff88
commit 5ab43ad039
No known key found for this signature in database
GPG Key ID: BA19ACF8FC8792F7

View File

@ -1,5 +1,18 @@
/**
* \file
* \brief [Linear search
* algorithm](https://en.wikipedia.org/wiki/Linear_search)
*/
#include <iostream>
/**
* Algorithm implementation
* \param [in] array array to search in
* \param [in] size length of array
* \param [in] key key value to search for
* \returns index where the key-value occurs in the array
* \returns -1 if key-value not found
*/
int LinearSearch(int *array, int size, int key) {
for (int i = 0; i < size; ++i) {
if (array[i] == key) {
@ -10,6 +23,7 @@ int LinearSearch(int *array, int size, int key) {
return -1;
}
/** main function */
int main() {
int size;
std::cout << "\nEnter the size of the Array : ";