#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define FD 'a'
#define IT ' '
typedef struct aaa
{
char ch;
struct aaa *next;
} AAA;
AAA *e_linkst()
{AAA *h;
h=(AAA *)malloc(sizeof(AAA));
h->next=NULL;
return h;
}
void creat_linkst(AAA * k)
{
AAA *p,*q;
int i,t;
char name[]="jessicarong";
t=strlen(name);
q=k;
for(i=0;i<t;i++)
{
p=(AAA *)malloc(sizeof(AAA));
p->ch=name[i];
p->next=NULL;
q->next=p;
q=p;
}
}
void print_linkst(AAA * h)
{ AAA * t;
t=h->next;
while(t!=NULL)
{
printf("%c ",t->ch);
t=t->next;
}
}
void insert(AAA *h,char a,char x)
{
AAA *s,*p,*q;
p=h->next; q=h;
while(p!=NULL)
{
if(p->ch==a)
{
s=(AAA *)malloc(sizeof(AAA)); //1.产生新节点
s->ch=x;//2.数据域赋值
s->next=p;//3.连
q->next=s;//4.断
}
q=p;
p=p->next;
}
s=(AAA *)malloc(sizeof(AAA));//1.产生新节点
s->ch=x; //2.数据域赋值
s->next=p;//3.连
q->next=s; //4.断
}
void find(AAA *h)//头插法
{
AAA *p,*q;
p=h->next;
q=h;
p->ch-=32;//j变大写
while(p)
{
q=p;
p=p->next;
if(q->ch==' '&&p->ch!=' ')
p->ch-=32;
}
}
int main()
{
AAA *head,*s,*p,*q,*t;
head=e_linkst(); //建立空链表
creat_linkst(head);//建立单链表
printf("\n原链表数据:\n");
print_linkst(head);//输出数据节点的值
printf("\n\n");
insert(head,FD,IT);//插入值为空格的新节点
printf("\n插入节点' '后链表数据:\n");
print_linkst(head);//输出数据节点的值
printf("\n\n");
find(head);
printf("\n更改后链表数据:\n");
print_linkst(head);
printf("\n\n");
}