From 26bef29a8398a2c84d5504fcec237a3746691331 Mon Sep 17 00:00:00 2001 From: Achlesha Varshney <89573471+Achlesha@users.noreply.github.com> Date: Wed, 5 Oct 2022 15:00:13 +0530 Subject: [PATCH] Create SearchingInAnArray.cpp --- cpp/SearchingInAnArray.cpp | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 cpp/SearchingInAnArray.cpp 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; +}