这是个数据结构的题目:大体的意思就是:用链式表进行插入和删除操作!
就两个错误:其中一个是:
void Initlist(Linklist*L){*L=null}错误!
还有一个是:Listinsert(Linklist L,int pos,char x[3]);错误!
大家帮帮忙忙,在这先谢过了!
下面是程序:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 20
#define M 20
#define null 0
typedef char Elemtype;
struct node
{
Elemtype data[N];
struct node*next;
}Lnode,*Linklist;
void Initlist(Linklist*L)//提示这错误!
{
*L=null;
}
status Listinsert(Linklist L,int pos,char w[3])//提示这错误
{
Linklist*p=L;
int j=0;
while (p&&j<pos-1)
{p=p->next;++j;}
if (!p||(j>pos-1)) return 0;
Linklist*s;
s=(Linklist)malloc(sizeof(Lnode));
strcpy(s->data,w);
s->next=p->next;
p->next=s;
return 1;
}
status Listdelete(Linklist L,Elemtype w[3])
{
Linklist p,q;
p=L;
while(p->next&&strcmp(p->data,w)!=0)
{p=p->next;++j;}
if(!(p->next)) return 0;
if(strcmp(p->data,w)==0)
{ q=p->next;
p->next=q->next;
free(q);
return 1;
}
void display(Linklist L)
{
Linklist q;
q=L;
printf("the list is :\n");
if(q==null)
printf("the list is null\n!");
else if(q->next==null)
printf("%s",q->data);
else
{
while (q->next!=null)
{printf("%s------->",q->data);
q=q->data;
}
printf("%s",q->data);
}
printf("\n");
}
int main()
{
Linklist L;
int flag=1,i,size,select,k;
char x[3],r[3];
char* T[M]={"APr","Jan","Jul","Jun","Mar","Mag"};
size=sizeof(*T)/3;
int i;
Initlist(&L);
printf("the data or arrange is:\n");
for(i=0;i<size;i++)
printf("%s",*T[i]);
while(flag)
{
printf("1----------> insert \n");
printf("2----------> delete \n");
printf("3----------> out \n");
printf("please input your select\n ");
scanf("%d",&select);
switch(select)
{
case 1:{printf("input your position\n");
scanf("%d",&k);
printf("input your data\n");
scanf("%s",x);
Listinsert(&L,k,x);
display(L);
prinf("\n");
}
break;
case 2:{ printf("\n input the data of your delete \n");
scanf("%s",r);
Listdelete(&L,r);
printf("\n");
display(L);
printf("\n");
}
break;
case 3: flag=0;
break;
}