diff --git a/cpp/SearchingInAnArray.cpp b/cpp/SearchingInAnArray.cpp new file mode 100644 index 0000000..08076a5 --- /dev/null +++ b/cpp/SearchingInAnArray.cpp @@ -0,0 +1,40 @@ +#include +struct Array +{ +int A[10]; +int size; +int length; +}; +void Display(struct Array arr) +{ +int i; +printf("\nElements are\n"); +for(i=0;ilength;i++) +{ +if(key==arr->A[i]) +{ +swap(&arr->A[i],&arr->A[0]); +return i; +} +} +return -1; +} +int main() +{ +struct Array arr1={{2,23,14,5,6,9,8,12},10,8}; +printf("%d",LinearSearch(&arr1,14)); +Display(arr1); +return 0; +}