diff --git a/Arrays-algos/reversearrayalgo2.cpp b/Arrays-algos/reversearrayalgo2.cpp new file mode 100644 index 0000000..7d8950a --- /dev/null +++ b/Arrays-algos/reversearrayalgo2.cpp @@ -0,0 +1,14 @@ +void reversearray2(int arr[],int size) +{ + + int rev[size]; + int j=0; + for(int i=size-1;i>=0;i++) + { + rev[j]=arr[i]; + j++; + } + + return rev; + +} \ No newline at end of file diff --git a/search-with-noob/a.exe b/search-with-noob/a.exe new file mode 100644 index 0000000..6d6e27f Binary files /dev/null and b/search-with-noob/a.exe differ diff --git a/search-with-noob/a.out b/search-with-noob/a.out new file mode 100644 index 0000000..05f1f11 Binary files /dev/null and b/search-with-noob/a.out differ diff --git a/search-with-noob/binary_search.cpp b/search-with-noob/binary_search.cpp index ab79acb..e2f86ce 100644 --- a/search-with-noob/binary_search.cpp +++ b/search-with-noob/binary_search.cpp @@ -23,13 +23,25 @@ int binary_search(int array[], int search, int lower, int upper) //Since the Binary Search needs a sorted array but we have an unsorted array so it needs to be sorted first. //You can use any sorting method as per your convenience. -int sort(int arr[],int search) +int sort(int arr[],int search, int size) { + for (int step = 0; step < size - 1; ++step) + { + for (int i = 0; i < size - step - 1; ++i) + { + if (arr[i] > arr[i + 1]) + { + int temp = arr[i]; + arr[i] = arr[i + 1]; + arr[i + 1] = temp; + } + } +} // You have to sort the array and call the binary function and return the result you get from that function to the main. - int result = binary_search(sorted_array_name, search_element, initial_lower_value, initial_upper value ); + int result = binary_search(arr, search, 0, size-1 ); return result; } @@ -41,7 +53,7 @@ int main() cout<<"Enter search element"<>search; int size = sizeof(array) / sizeof(array[0]); - int result = sort(array, search); + int result = sort(array, search,size); if (result == -1) cout<<"Element not found"<