#include
typedef struct element *Hash;
struct element
{
int x;
int hash;
int position;
Hash next;
};
void Insert(int hash,int position,int x,Hash P)
{
Hash tmp;
if(tmp==NULL){
printf("Out of Space!");
}
else{
tmp->x=x;
tmp->hash=hash;
tmp->position=position;
tmp->next=P->next;
P->next=tmp;
}
}
Hash FindPosition(int hash,int position,int x,Hash L)
{
int i,count; Hash P;
count=position-hash;
P=L;
if(count>0){
while(count>=0){
if(P->positionposition>=hash){
P=P->next;
count--;
}
else if(x>P->x){
P=P->next;
}
if(P->next==NULL) break;
}
}
else if(count==0)
{
while(x>P->x) P=P->next;
}
else
{
count+=11;
while(count>0){
if(P->positionposition>position){
P=P->next;
count--;
}
else if(x>P->x)
{
P=P->next;
}
if(P->next==NULL) break;
}
}
return P;}
void Printresult(Hash L)
{
while(L!=NULL){
printf("%d",L->x);
L=L->next;
}
}
int main(void){
int N,i,x,hash;
Hash P,L,tmp;
scanf("%d",&N);
scanf("%d",&x);
L=malloc(sizeof(struct element));
if(L==NULL){ printf("Out of Space!"); }
else{
L->x=x;
L->hash=x%N;
L->position=0;
L->next=NULL;
}
for(i=1;i<N;i++){
scanf("%d",x);
if(x<0) hash="x%N;"
p="L-">next;
L->next=NULL;
while(P!=NULL){
tmp=P->next;
free(P);
P=tmp;
}
free(L);
}
只改了编译错误,逻辑上有无错误没看
好像把程序拷过来的时候有点问题……你提供的代码还是有段错误诶……
追答把error贴出来撒
追问编译通过了的,但是运行的时候有问题,调试的时候出现了Program stopped at 0x7559ecc0.It is stopped with signal SIGSEGV,Segmentation fault.是段错误,好像是因为内存分配问题引起的,但是不知道是代码的哪里错了。
追答for(i=1;i<N;i++)只改了编译错误,逻辑上有无错误没看,因为我并不清楚你这个程序到底是要实现什么功能的,不过你这个for循环很有问题,L已经free了,就不应该再继续循环下去,否则执行到P = L->next的时候会崩溃