标签:clu sort temp ges for std names class out
#include <iostream> using namespace std; int a[10]; int temp[10]; void mergeArray(int left,int right,int mid){ int i = left; int j = mid + 1; int k = 0; while( i <= mid && j <= right) { if(a[i] < a[j]){ temp[k++] = a[i++]; } else { temp[k++] = a[j++]; } } while( i<=mid ){ temp[k++] = a[i++]; } while( j<=right ){ temp[k++] = a[j++]; } k = 0; while(left <= right ){ a[left++] = temp[k++]; } } void mergeSort(int left,int right){ if(left < right){ int mid = (left+right)/2; mergeSort(left,mid); mergeSort(mid+1,right); mergeArray(left,right,mid); } } int main() { int n; cin>>n; for(int i=0;i<n;i++){ cin>>a[i]; } mergeSort(0,n-1); for(int i=0;i<n;i++){ cout<<a[i]<<endl; } return 0; }
标签:clu sort temp ges for std names class out
原文地址:http://www.cnblogs.com/rimochiko/p/7587272.html