数据结构
# include<stdio.h># include<stdlib.h>
typedef struct linknode
{int data;
struct linknode *next;
}node, *linklist;
void Createlist(linklist L)
{node *head,*p,*s;
int n=0,z=1;
int x;
head=malloc(sizeof(node));
p=head;
printf("\n\t\t 建立一个线性表");
printf("\n\t\t 请逐个输入结点,以"x"未结束标记! \n");
while(z)
{printf("\t\t 输入:");
scanf("%c",&x);
getchar();
if(x!='x')
{s=NULL;
n++;
s->data=x;
p->next=s;
s->next=NULL;
p=s;
}
else z=0;
}
}
int Lenlist(linklist L)
{node *p=L;
int n=0;
while(p->next)
{p=p->next; n++ }.....................................................(34)
return n;
}
node *Searchlist(linklist L,int i)
{node *p=L;
int j=0;
while(p->next!=NULL&&j<1)
{p=p->next;
j++;
}
if(j==1)
return p;
else
return NULL;
}
void Inslist(linklist L,int i,int x)
{node *head,*s,*p;
int n,j=0;
p=head;
while(p!=NULL&&j<1)
{j++;
p=p->next;
}
if(p!=NULL)
{s=NULL;
s->data=x;
s->next=p->next;
p->next=s;
n++;
}
else
printf("\n\t\t线性表为空或插入位置超出! \n");.............................................(14)
}
void Dellist(linklist L,int x)
{int n;
node *head,*p,*q;
if(head==NULL)
{printf("\t\t链表下溢! \n");
return;
}
if(head->next==NULL)
{printf("\t\t线性表已经为空!\n");
return;
}
q=head;
p=head->next;
while(p!=NULL&&p->data!=x)
{q=p;
p=p->next;
}
if(p!=NULL)
{q->next=p->next;
delete (P);..................................................................(86)
n--;
printf("\t\t %c已经被删除!",x);
}
else
printf("\t\t未找到!\n");
}
void main()
{linklist L;
int n=0,i;
int x;
Createlist(L);
Lenlist(L,n);.............................................................(98)
Searchlist(L,i);
Inslist(L,i,x);
Dellist(L,x);
}
请帮看看,我运行了搞不出来啊。。。(14) (34) (86) (98)有错!!!!!!!!!!!!!