From f258fd6390402f1c01181c85d6a1c051e6a7cb3d Mon Sep 17 00:00:00 2001 From: 17-Vishal Date: Mon, 7 Oct 2019 02:48:46 +0530 Subject: [PATCH] Added STL Folder --- C++ STL/Binary Search using STL.cpp.txt | 29 +++++++++++++++++++++++++ C++ STL/Sort using STL.cpp.txt | 16 ++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 C++ STL/Binary Search using STL.cpp.txt create mode 100644 C++ STL/Sort using STL.cpp.txt diff --git a/C++ STL/Binary Search using STL.cpp.txt b/C++ STL/Binary Search using STL.cpp.txt new file mode 100644 index 0000000..861e31c --- /dev/null +++ b/C++ STL/Binary Search using STL.cpp.txt @@ -0,0 +1,29 @@ +#include +#include +using namespace std; + +void show(int a[], int arraysize) +{ + for (int i = 0; i < arraysize; ++i) + cout << a[i] << " "; +} + +int main() +{ + int a[] = { 2, 5, 12, 7, 24, 8, 1, 43, 10, 0 }; + int asize = sizeof(a) / sizeof(a[0]); + + sort(a, a + asize); + + if (binary_search(a, a + 10, 8)) + cout << "\nElement found in the array"; + else + cout << "\nElement not found in the array"; + + if (binary_search(a, a + 10, 10)) + cout << "\nElement found in the array"; + else + cout << "\nElement not found in the array"; + + return 0; +} \ No newline at end of file diff --git a/C++ STL/Sort using STL.cpp.txt b/C++ STL/Sort using STL.cpp.txt new file mode 100644 index 0000000..32b40d2 --- /dev/null +++ b/C++ STL/Sort using STL.cpp.txt @@ -0,0 +1,16 @@ +#include +using namespace std; + +int main() +{ + int arr[] = {1, 5, 8, 9, 6, 7, 3, 4, 2, 0}; + int n = sizeof(arr)/sizeof(arr[0]); + + sort(arr, arr+n); + + cout << "Sorted Array is : "; + for (int i = 0; i < n; ++i) + cout << arr[i] << " "; + + return 0; +} \ No newline at end of file