void sortmerge(int p,int r){
if(p<r){
	int q=(p+r)/2;
	sortmerge(p,q);
	sortmerge(q+1,r);
	merge(p,q,r);
	}
}
Beispiel #2
0
void MySort::sortmerge(int* a,int* aux,int lo,int hi)
{
	if(hi<=lo) return;
	int mid=lo+(hi-lo)/2;
	sortmerge(a,aux,lo,mid);
	sortmerge(a,aux,mid+1,hi);
	if(!less(a[mid+1],a[mid])) return;
	merge(a,aux,lo,mid,hi);
}
Beispiel #3
0
struct node* sortmerge(struct node* a,struct node* b)
{
    struct node* result=NULL;
 if(a==NULL)
    return b;
 if(b==NULL)
    return a;
    if(a->data<=b->data)
    {
        result=a;
        result->next=sortmerge(a->next,b);
    }
    else
    {
        result=b;
        result->next=sortmerge(a,b->next);
    }
    return result;
}
Beispiel #4
0
struct node* merge(struct node** head)
{
    struct node* ptr=*head;
    struct node* a;
    struct node* b;
    if(ptr==NULL || (ptr->next==NULL))
       return;
       split(ptr,&a,&b);
       merge(&a);
       merge(&b);
       *head=sortmerge(a,b);
}
int main(){
int t,n;
int i,j;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		A=(order*)malloc((n+1)*sizeof(order));
		for(i=1;i<=n;i++)
			scanf("%d%d%d",&A[i].s,&A[i].e,&A[i].c);
		sortmerge(1,n);

		optimal=(int *)malloc((n+1)*sizeof(int));
		for(i=1;i<=n;i++) optimal[i]=-1;
		for(i=1;i<=n;i++){
			j=comp_optimal(i);
		}
		printf("%d\n",optimal[n]);
		free(optimal);
		free(A);
	}
return 0;
}
Beispiel #6
0
void MySort::MergeSort(int* a,int length)
{
	int* aux = new int[length];
	sortmerge(a,aux,0,length-1);
}