归并排序

2014-11-23 21:27:55 · 作者: · 浏览: 11
#include
using namespace std;


void sort(int a[],int first,int mid,int last,int temp[])
{
	int i=first;
	int j=mid;
	int count=0;
	while(1)
	{
		if(a[i]
first) { int mid=(first+last)/2; merge(a,first,mid,temp); merge(a,mid+1,last,temp); sort(a,first,mid,last,temp); } } void main() { int a[]={1,4,7,9,12,2,5,9,11,13}; int last=sizeof(a)/sizeof(int); int* p =new int[last](); merge(a,0,last,p); for(int i=0;i