From 45ae0912a24ff4f1f953f8c0a803f2a1be2ab301 Mon Sep 17 00:00:00 2001 From: MEGHWANT SINGH <68533246+Meghwantsingh@users.noreply.github.com> Date: Sun, 3 Oct 2021 08:09:00 +0530 Subject: [PATCH 1/4] Create binary-search.cpp --- .../searching/binary-search/binary-search.cpp | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 arrays/searching/binary-search/binary-search.cpp diff --git a/arrays/searching/binary-search/binary-search.cpp b/arrays/searching/binary-search/binary-search.cpp new file mode 100644 index 0000000..5c0fab7 --- /dev/null +++ b/arrays/searching/binary-search/binary-search.cpp @@ -0,0 +1,49 @@ + +//Binary search .................Iterative method best for sorted array + +# include +using namespace std; //std::cout or std::cin + +int main(){ + int n,t; + cout<<"enter test cases"<>t; + //cout<<(sizeof(arr)/sizeof(arr[0])); sizeof(arr) = datatype of arr * number of variable + while(t--){ + cout<<"enter size of array "<>n; + int arr[n]; + + cout<<"Enter array element\n"; + + for(int i=0;i>arr[i]; + } + + int key; + cout<<"enter key to search"<>key; + + int low=0,high=n-1, flag=0; + for(int i=0;ikey){ + high= mid-1; + } + else if(arr[mid] Date: Mon, 4 Oct 2021 11:04:36 +0530 Subject: [PATCH 2/4] Create linear-search.cpp --- .../searching/linear-search/linear-search.cpp | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 arrays/searching/linear-search/linear-search.cpp diff --git a/arrays/searching/linear-search/linear-search.cpp b/arrays/searching/linear-search/linear-search.cpp new file mode 100644 index 0000000..af35591 --- /dev/null +++ b/arrays/searching/linear-search/linear-search.cpp @@ -0,0 +1,39 @@ +//Linear search key + +#include +using namespace std; +int main(){ + int n; // size of array + cout<<"enter size of array"<>n; + int arr[n]; // array to store all the elements + cout<<"Enter array element\n"; + for(int i=0 ;i>arr[i]; // loop for entering array + } + int key; // key variable to be search + cout<<"enter key to be search"<>key; + int i =0 ,flag =0 ,count =0,lastpos; + for(i =0 ; i Date: Mon, 4 Oct 2021 11:20:40 +0530 Subject: [PATCH 3/4] Update linear-search.cpp lastpos is used to give position of key to be search. --- arrays/searching/linear-search/linear-search.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/arrays/searching/linear-search/linear-search.cpp b/arrays/searching/linear-search/linear-search.cpp index af35591..e776c12 100644 --- a/arrays/searching/linear-search/linear-search.cpp +++ b/arrays/searching/linear-search/linear-search.cpp @@ -2,11 +2,13 @@ #include using namespace std; + int main(){ - int n; // size of array + int n; // size of array cout<<"enter size of array"<>n; int arr[n]; // array to store all the elements + cout<<"Enter array element\n"; for(int i=0 ;i>arr[i]; // loop for entering array @@ -30,10 +32,9 @@ int main(){ if(flag == 0){ cout<<"Not present"< Date: Tue, 5 Oct 2021 10:52:42 +0530 Subject: [PATCH 4/4] Create reversearray.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reverse an array problem done using C++ .Pls check if you got any error or mistake replay. Github 👍 https://github.com/Meghwantsingh/Data-Structures-and-Algorithms/new/main/arrays/reverse-array If I did something wrong sorry bez I am new to this. --- arrays/reverse-array/reversearray.cpp | 39 +++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 arrays/reverse-array/reversearray.cpp diff --git a/arrays/reverse-array/reversearray.cpp b/arrays/reverse-array/reversearray.cpp new file mode 100644 index 0000000..f8ff925 --- /dev/null +++ b/arrays/reverse-array/reversearray.cpp @@ -0,0 +1,39 @@ + +// REVERSE AN ARRAY + +#include +using namespace std; + +void reArr(int arr[],int start ,int last){ // function to reverse array + + int temp; + + while(start >n; + int arr[n]; + cout<<"Enter the element of array\n"; + + for(int i=0;i>arr[i]; + } + reArr(arr,0,n-1); // function for reverse array element + cout<<"Reversed array\n"; + + for(int i=0;i