/* 头文件的包含应写清楚 */
#include
#include
/* 原来的定义方式虽然可以,但是比较奇怪 */
typedef struct element
{
int x;
int hash;
int position;
struct element* next;
}S_HASH;
typedef S_HASH* Hash;
void Insert(int hash,int position,int x,Hash P)
{
Hash tmp = NULL; /* 未初始化,会导致接下来的if语句判断无效 */
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 count;
Hash P;
count=position-hash;
P=L;
if(count>0)
{
while(count>=0)
{
if(P->position>=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->position>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 = (Hash)malloc(sizeof(struct element));/* malloc时需指明数据类型 */
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{
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);
}
} /* 缺少一个} */
只改了编译错误,逻辑上有无错误没看