这次编译通过了,汗~
#include<stdio.h>
#define MAXSIZE 100
#define NULL 0
typedef struct node
{char data;
struct node *next;
}Node,*Linklist;
/*****************************************************************************/
Linklist Create() //用头插法创建链表
{int flag=1;
Linklist head;
Node *s;
char c;
head=(Linklist)malloc(sizeof(Node));
head->next=NULL;
while(flag)
{c=getchar();
if(c!='$')
{s=(Node *)malloc(sizeof(Node));
s->data=c;
s->next=head->next;
head->next=s;
}
else flag=0;
}
return(head);
}
/*****************************************************************************/
main()
{int i=0,j=1; //创建链表进行插入,删除,查找,查找并且插入数据,显示等操作
char key,b;
Linklist head;
printf("请先给链表进行初始化!完毕后用$结束\n");
head=Create();
printf("请输入您所要进行的操作!\n");
while(j)
{printf("1.插入 2.删除 3.查找 4.查找并且插入数据 5.显示全部链表数据 6.退出\n");
scanf("%d",&i);
//if(i==1) //插入
//test1();
//if(i==2) //删除
//test2();
// if(i==3) //查找
// test3();
if(i==4) //查找并插入数据
{printf("请输入你所要查找的数据!\n");
key=getchar();
printf("请输入你所要插入的数据!\n");
b=getchar();
test4(head,key,b);
}
if(i==5) //显示
test5(head);
if(i==6)
break;
}
}
/************* *************************************************************/
test4(Linklist head,char key,char b)
{Linklist p,q;
p=head->next;
while(p!=NULL)
if(p->next->data!=key)
p=p->next;
else break;
q=(Linklist)malloc(sizeof(Node));
q->data=b;
q->next=p->next;
p->next=q;
}
/**************************************************************************/
test5(Linklist head)
{Linklist l;
l=head->next;
while(l->next!=NULL)
{printf("%c ",l->data);}
printf("\n");
}