标签:code clu sort pac oid cto 实现 log merge
#include<iostream> using namespace std; #include<vector> #include "Vector.h" void merge(int num[], int tem[], int lo, int hi); //归并排序 void mergesort(int num[],int tem[], int lo, int hi) { //int *tem01; if (hi - lo == 0 ) tem[lo] = num[lo]; else { int mid = (lo + hi) >> 1; mergesort(num, tem,lo, mid); mergesort(num, tem, mid+1, hi); merge(num, tem, lo, hi);//tem01是两个变量的中转站 } } void merge(int num[], int tem[], int lo, int hi) { int mid = (lo + hi) >> 1; int n = mid + 1; if ((lo <= mid) && (mid + 1 <= hi || num[lo] > tem[mid + 1])) { num[lo++] = tem[lo++]; } if ((mid + 1 <= hi) && (lo <= mid || num[lo] < tem[mid + 1])) { num[lo++] = tem[(n)++]; } } int main() { int v1[10] = {1,2,3,0,9,8,7,6,5,4}; int v2[10]; mergesort(v1,v2, 0,9); for (int i = 0; i < 10; i++) { cout << v2[i]<< endl; } system("pause"); }
标签:code clu sort pac oid cto 实现 log merge
原文地址:http://www.cnblogs.com/xiaochige/p/7586994.html