代码如下,但运行什么也没有;纯属小白,求大神指教
#include<stdio.h>
#include<malloc.h>
typedef int datatype;
typedef struct Node
{
datatype data;
struct Node *next;
}LNode;
void ListInitiate(LNode **fakeh)
{
*fakeh=NULL;
}
int ListGet(LNode *fakeh,int i,datatype *x)
{
int j = 0;
LNode *p = fakeh;
if (i<0)
return 0;
else
{
while (p->next!=NULL&&j<i)
{
j++;
p = p->next;
}
}
if (j!=i)
{
printf("插入位置错误");
return 0;
}
*x=p->data;
return 0;
}
int ListInsert(LNode *fakeh,int i,datatype x)
{
LNode *p=fakeh;
LNode *q,*s;
int j=0;
if(i<0)
{
printf("插入位置出错");
return 0;
}
s=(LNode *)malloc(sizeof(LNode));
if(i==0)
{
s->next=p;
fakeh=s;
}
else
{
while(p->next!=NULL&&j<i-1)
{
p=p->next;
j++;
}
if(j!=i-1)
{
printf("插入位置错误");
return 0;
}
else
{
q=p->next;
s->next=q;
p->next=s;
}
}
}
void main()
{
LNode *fakeh;
datatype x;
int i;
ListInitiate(&fakeh);
for(i=0;i<10;i++)
{
ListInsert(fakeh,i,i++);
}
for(i=0;i<10;i++)
{
ListGet(fakeh,i,&x);
printf("%d",x);
}
}