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