"0x004010e9"指令引用的"0x00000078"内存。该内存不能为"read"。
"0x004010e9"指令引用的"0x00000078"内存。该内存不能为"read"。我在编快速排序的算法,但是出现了这个状况。一下是我的代码:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
typedef int KeyType;
typedef int DataType;
struct RecordNode{
KeyType key;
DataType info;
};
struct SortObject{
int n; /* n为文件中记录个数 */
RecordNode * record;
};
void quicksort(SortObject *p,int l,int x); /* 快排函数 */
void quicksort(SortObject *pvector, int left, int r)
{
int i,j;
RecordNode temp;
if(left>=r) return;
i=left; j=r;
temp = pvector->record[i];
while(i!=j){
while( (j>i)&&(pvector->record[j].key >= temp.key) )
j--;
if(j>i)
pvector->record[i++] = pvector->record[j];
while( (j>i)&&(pvector->record[i].key <= temp.key) )
i++;
if(i<j)
pvector->record[j--] = pvector->record[i];
}
pvector->record[i] = temp;
quicksort(pvector, left, i-1);
quicksort(pvector, i+1, r);
}
void main()
{
srand(time(0));
int len,k;
printf("Please input the length of record:\n");
scanf("%d",&len);
//为记录数组申请结点空间
SortObject * p1 = (SortObject*)malloc(sizeof(SortObject));
if(p1 != NULL){ //申请成功
p1->record = (RecordNode *)malloc(sizeof(int)*len);
if(p1->record){
p1->n = len;
}
else free(p1);
}
else printf("Out of space!!\n");
int num=len;
while(num--)
p1->record[num].key = rand()%1000;
printf("The new record is:\n%d",p1->record[0].key);
for( k=1; k<len; k++)
printf("--%d",p1->record[k].key);
quicksort(p1,0,p1->n-1);
printf("\n\nThe sorted record is:\n%d",p1->record[0].key);
for( k=1; k<len; k++)
printf("--%d",p1->record[k].key);
}
到底是哪里出错了呢?