-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMergeSort.cpp
More file actions
63 lines (56 loc) · 1.26 KB
/
MergeSort.cpp
File metadata and controls
63 lines (56 loc) · 1.26 KB
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
54
55
56
57
58
59
60
61
62
63
#include <bits/stdc++.h>
using namespace std;
void merge(vector<int>& arr,int left,int mind,int right,vector<int>& tem){
int i = left;
int j = mind+1;
int t = 0;
while(i<=mind&&j<=right){
if(arr[i]<=arr[j]){
tem[t++] = arr[i++];
}else{
tem[t++] = arr[j++];
}
}
while(i<=mind){
tem[t++] = arr[i++];
}
while(j<=right){
tem[t++] = arr[j++];
}
t = 0;
while(left<=right){
arr[left++] = tem[t++];
}
}
void mergeSort(vector<int>& arr,int left,int right,vector<int>& tem){
if(left<right){
int mind = (left+right)/2;
mergeSort(arr,left,mind,tem);
mergeSort(arr,mind+1,right,tem);
merge(arr,left,mind,right,tem);
}
}
void check(int i){
char* t = (char *)&i;
if(*t==1){
cout<<"xiao"<<endl;
}else{
cout<<"da"<<endl;
}
}
int main(){
/*vector<int> arr{49, 38, 65, 97, 23, 22, 76, 1, 5, 8, 2, 0, -1, 22};
vector<int> tem(arr.size());
mergeSort(arr,0,arr.size()-1,tem);
for(int i=0;i<arr.size();i++){
cout<<arr[i]<<endl;
}*/
int i = 45;
char* t = (char *)&i;
if(*t==1){
cout<<"xiao"<<endl;
}else{
cout<<"da"<<endl;
}
system("pause");
}