-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMergeSort.cpp
More file actions
53 lines (39 loc) · 876 Bytes
/
MergeSort.cpp
File metadata and controls
53 lines (39 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include<iostream>
#include <cstdlib>
using namespace std;
void printArray(int a[], int _size) {
for(int i=0; i<_size; i++) {
std::cout<<a[i]<<"\t";
}
}
void mergeArray(int left[], int right[], int a[] ) {
}
void mergeSort(int a[], int _size) {
if(_size <2) {
return;
}
int mid = _size/2;
// Create Array
int left[mid];
int right[_size-mid];
//Copy Array
for(int i=0; i<mid; i++) {
left[i] = a[i];
}
for(int j=mid; j<_size; j++) {
right[_size-j] = a[j];
}
//Merger sort left
mergeSort(left,mid);
mergeSort(right,_size-mid);
// Final merge
mergeArray(left,right, a);
}
int main() {
int arr[] = {12,11,13,5,6};
int _size = (sizeof(arr)/sizeof(int));
std::cout<<" Given Array is "<<endl;
printArray(arr,_size);
// Merge Sort
return 0;
}