#include <stdio.h> #define len sizeof(struct a) #include <malloc.h>
struct a {char lk; struct a *next ; };
main() {struct a *head,*p,*q,*s; int i; char ch; head=p=(struct a *) malloc(len); for(i=1;i<=26;i++) { (p->lk)=('a'+i-1); p->next=(struct a *)malloc(len); p=p->next;
} p->next=NULL;
p=head; while (p->next != NULL)
{ printf("%c ",p->lk); p=p->next; } /* printf("\n"); */
q=p=head; printf("\ninput deleted letter:"); scanf("%c",&ch); while(ch != '0') { q=p=head;
while(p->lk != ch && p->next != NULL) {q=p; p=p->next;} if(p==head) { head=head->next;free(p); } else { if(p->lk == ch)
{ q->next=p->next; free(p) ; } else printf("can't find it"); }
q=p=head; printf("\n"); while (p->next != NULL)
{ printf("%c ",p->lk); p=p->next; } /* printf("\n"); */
q=p=head;
printf("\n2:input deleted letter"); fflush(stdin); scanf("%c",&ch); }
p=head; while(p->next != NULL) {printf("%c",p->lk); p=p->next;}
q=p=head; printf("\ninput insert letter"); /*insert */ scanf("%c",&ch); 这句为什么没执行啊``````为什么插入只能插一个```急`` fflush(stdin); while(ch != '0') { q=p=head; while(p->lk < ch && p->next != NULL) { q=p; p=p->next;} if(p==head) { s=(struct a *) malloc(len); s->lk=ch; s->next=head; q=p=s; }
else { if (p->lk == ch) printf("inserted is exist"); else {s=(struct a *) malloc(len); s->lk=ch; s->next=p; q->next=s; q=p=head;} }
while(p->next != NULL) {printf("%c",p->lk); p=p->next;} p=head; printf("\n2insert a letter");
scanf("%c",&ch); fflush(stdin);
}
}