From 9c8b68fbc9804e8747d69130ba8b55823f7f9635 Mon Sep 17 00:00:00 2001 From: Aashish Sharma <67376025+Aashishsharma99@users.noreply.github.com> Date: Sat, 31 Oct 2020 10:06:57 +0530 Subject: [PATCH] Create Sorting.cpp --- Sorting.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Sorting.cpp diff --git a/Sorting.cpp b/Sorting.cpp new file mode 100644 index 0000000..387db96 --- /dev/null +++ b/Sorting.cpp @@ -0,0 +1,38 @@ + +play_arrow + +brightness_4 +// C++ progrma to sort an array +#include +#include + +using namespace std; + +void show(int a[], int array_size) +{ + for (int i = 0; i < array_size; ++i) + cout << a[i] << " "; +} + +// Driver code +int main() +{ + int a[] = { 1, 5, 8, 9, 6, 7, 3, 4, 2, 0 }; + + // size of the array + int asize = sizeof(a) / sizeof(a[0]); + cout << "The array before sorting is : \n"; + + // print the array + show(a, asize); + + // sort the array + sort(a, a + asize); + + cout << "\n\nThe array after sorting is :\n"; + + // print the array after sorting + show(a, asize); + + return 0; +}