Runtime error (access violation) Please help me !! sad......
Posted by
xinxin 18 Sep 2016 19:06
#include<stdio.h>
void merge(int a[],int b[],int c[],int d[],int left,int mid,int right)
{
int i=left,j=mid+1;
int k=left;
while((i<=mid)&&(j<=right))
{
if(a[i]>=a[j])
{b[k++]=a[i++];
k--;
i--;
d[k++]=c[i++];}
else
{b[k++]=a[j++];
k--;
j--;
d[k++]=c[j++];}
}
if(i>mid)
for(int q=j;q<=right;q++)
{b[k++]=a[q];
k--;
d[k++]=c[q];
}
else if(j>right)
for(int q=i;q<=mid;q++)
{b[k++]=a[q];
k--;
d[k++]=c[q];}
for (int l = left;l <= mid;l++) {
a[l] = b[l];
c[l]=d[l];
}
for (int l = mid+1;l <= right;l++) {
a[l] = b[l];
c[l]=d[l];
}
}
void mergesort(int a[],int b[],int c[],int d[],int left,int right)
{
if(left<right)
{
int mid = (left + right) / 2;
mergesort(a,b,c,d,left,mid);
mergesort(a,b,c,d,mid+1,right);
merge(a, b,c,d, left, mid, right);
}
}
int main()
{
int n,i;
int c[15000],a[15000],b[15000],d[15000];
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&c[i]);
scanf("%d",&a[i]);
}
mergesort(a,b,c,d,0,n-1);
for(i=0;i<n;i++)
{
printf("%d %d\n",d[i],b[i]);
}
fflush(stdin);
getchar();
return 0;
}
Re: Runtime error (access violation) Please help me !! sad......
Sorry then :)
Anyways, feel free to look into older threads of corresponding tasks, they might contain hints for your questions.