From b7e4e7565d0567e752d3efd5a90435ae6c6eef67 Mon Sep 17 00:00:00 2001 From: abdurrezzak Date: Sat, 21 Oct 2017 15:08:39 +0300 Subject: [PATCH] Add files via upload --- 3.MergeSort.cpp | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 3.MergeSort.cpp diff --git a/3.MergeSort.cpp b/3.MergeSort.cpp new file mode 100644 index 0000000..ea8adf7 --- /dev/null +++ b/3.MergeSort.cpp @@ -0,0 +1,76 @@ +/* + * This program takes an array from the user + * sorts it using merge sort + * Prints the sorted array + * Time Complexity of the algorithm is: O(nlogn) + * + * For more information about Merge Sort Algorithm: https://en.wikipedia.org/wiki/Merge_sort + * + * Coded by: Abdurrezak EFE + * + * */ +#include +#include +using namespace std; + +void merge(int arr[], int l, int m, int r) //merge function O(n) +{ + int lsize = m-l+1; + int rsize = r-m; + + int left[lsize]; + int right[rsize]; + + for(int i=0;i> k; + + int arr[k]; + for(int i=0;i> arr[i]; + + merge_sort(arr,0,k-1); //sorting + + for(int i=0;i