标签:pac i++ mes 归并 clu div temp amp out
#include<iostream> #include<cstring> #include<vector> #include<algorithm> #include<map> using namespace std; void merge(int A[], int left,int mid,int right){ int p1 = left; int p2 = mid + 1; int temp[right-left+1]; int i = 0; while(p1 <= mid && p2 <= right){ temp[i++] = A[p1] > A[p2] ? A[p2++] : A[p1++]; } while(p1 <= mid){ temp[i++] = A[p1++]; } while(p2 <= right){ temp[i++] = A[p2++]; } for(int i = left; i <= right; i++){ A[i] = temp[i-left]; } } void sort(int A[], int left,int right) { if(left == right){ return; } int mid = left + ((right-left) >> 2); sort(A,left,mid); sort(A,mid+1,right); merge(A,left,mid,right); } int main(){ int a[] = {5,4,7,9,3,8,2,1}; sort(a,0,8); for(int i = 0; i < 8;i++){ cout<<a[i]<<" "; } return 0; }
标签:pac i++ mes 归并 clu div temp amp out
原文地址:https://www.cnblogs.com/buaaZhhx/p/12063608.html