#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct node
{
char a[10];
struct node *next;
}linknode, *linklist;
void main()
{
linklist head,p;
char string[20],
head=creatlist();
printf("the former linklist is:\n");
traverselist(head);
printf("input the deleted string:");
scanf("%s",string);
p=check(head,string);
delelistnode(head,p,string);
prinf("the later linklist is :\n");
traverselist(head);
}
linklist creatlist( )//尾插入法建立链表
{ linklist head,r;
char string[20];
head=(linklist)malloc(sizeof(linknode));
head->next=NULL;
r=head;
printf("input a string(输入#为结束):");
scanf("%s",string);
while(strcmp(string,'#'))
{
(linklist)p=(linklist)malloc(sizeof(listnode));
p=check(head,string);//检查是否有重复的字符串输入
if(p==NULL)
{
strcpy(p->a,string);
p->next=NULL;
r->next=p;r=p;
}
printf("input a string(输入#为结束):");
scanf("%s",string);return head;
}
linklist check(linklist head,char string[20])
{
(linklist)r=head->next;
while(strcpy(r->a,string)&&r)
{
r=r->next;
}
return r;
}
delelistnode(linklist head,linklist p,char string[30])
{
(linklist)r=head->next;
while(r->next!=p)
r->next=r;
r->next=p->next;
free(p);
}
traverselist(linklist head)
{ linklist r;
r=head->next;
while(r)
printf("%s ",r->a);
}
运行软件为VC6.0