From d4d72756e318621bb2cd06f9850a9d6442f2b77d Mon Sep 17 00:00:00 2001 From: Abhishek Date: Fri, 2 Oct 2020 10:31:21 -0700 Subject: [PATCH 1/2] Added merge sort in c++ folder --- C++/merge_sort.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 C++/merge_sort.cpp diff --git a/C++/merge_sort.cpp b/C++/merge_sort.cpp new file mode 100644 index 00000000..0971dfe8 --- /dev/null +++ b/C++/merge_sort.cpp @@ -0,0 +1,66 @@ +#include +using namespace std; +void swapping(int &a, int &b) { + int temp; + temp = a; + a = b; + b = temp; +} +void display(int *array, int size) { + for(int i = 0; i> n; + int arr[n]; //create an array with given number of elements + cout << "Enter elements:" << endl; + for(int i = 0; i> arr[i]; + } + cout << "Array before Sorting: "; + display(arr, n); + mergeSort(arr, 0, n-1); //(n-1) for last index + cout << "Array after Sorting: "; + display(arr, n); +} \ No newline at end of file From 27fbb138a02980c4a7058f8835540809e04dd8de Mon Sep 17 00:00:00 2001 From: Abhishek Date: Fri, 2 Oct 2020 10:36:47 -0700 Subject: [PATCH 2/2] Added Quick sort in c++ folder --- C++/quick_sort.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 C++/quick_sort.cpp diff --git a/C++/quick_sort.cpp b/C++/quick_sort.cpp new file mode 100644 index 00000000..c8558f7b --- /dev/null +++ b/C++/quick_sort.cpp @@ -0,0 +1,69 @@ +#include +using namespace std; +void swapping(int &a, int &b) { //swap the content of a and b + int temp; + temp = a; + a = b; + b = temp; +} +void display(int *array, int size) { + for(int i = 0; i> n; + int arr[n]; //create an array with given number of elements + cout << "Enter elements:" << endl; + for(int i = 0; i> arr[i]; + } + cout << "Array before Sorting: "; + display(arr, n); + mergeSort(arr, 0, n-1); //(n-1) for last index + cout << "Array after Sorting: "; + display(arr, n); +} \ No newline at end of file