求解哪里产生了违例访问?
#include<iostream>#include<fstream>
#include<stdlib.h>
//#include<time.h>
//#include <algorithm>
using namespace std;
#define length 100
int partition(int a[],int m,int n)
{
int i=m;
int j=n+1;
int x=a[m];
while(1)
{
while(a[++i]<x);
while(a[--j]>x);
if(i>=j)
break;
else{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
void quicksort(int a[],int m,int n)
{
if(m<n)
{
int q=partition(a,m,n);
quicksort(a,m,q-1);
quicksort(a,q+1,n);
}
}
int main()
{
int a[length];
// time_t start,end;
int i;
// srand((unsigned)time(NULL));
ifstream fin;
fin.open("random_number.txt");
if(!fin)
{
cout<<"can not open file 'random_number.txt'";
return -1;
}
else
{
for(i=0;i<length;i++)
{
fin>>a[i];
}
}
fin.close();
// start=clock();
quicksort(a,0,length-1);
// end=clock();
for(i=0;i<length;i++)
{
printf("%d",a[i]);
}
system("pause");
//return 0;
}