#include <stdio.h> #define len sizeof(struct a) #include <malloc.h>
typedef struct b {char lk; struct b *next ; }a,*Linklist;
void output(a *head){ a *p; p=head; while (p != NULL)
{ printf("%c ",p->lk); p=p->next; } printf("\n"); }
Linklist Deletechar(a *head) {a *p,*q,*o; char ch; o=q=p=head; printf("\ninput deleted letter:"); scanf("%c",&ch); while(ch != '0') { q=p=head;
while(p->lk != ch && p != 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 "); } printf("deleted ago is :\n"); output(head); printf("plese input delete char:\n"); fflush(stdin);/*在此加上清流函数 */ scanf("%c",&ch); } return o; } Linklist insert(a *head) { a *p,*q,*s,*o; char ch; o=q=p=head; printf("\ninput insert letter:"); fflush(stdin); scanf("%c",&ch); while(ch != '0') { q=p=head; while(p->lk < ch && p != NULL) { q=p; p=p->next;}
if(p == head) { if(p->lk==ch) {printf("it is exist !!!!\n");} else
{ if((s=(a *)malloc(sizeof(a)))==NULL) exit(1); /*s=(struct a *) malloc(len);*/ s->lk=ch; s->next=p; head=p=s;} } else { if(p->lk != ch) { if((s=(a *)malloc(sizeof(a)))==NULL) exit(1); /*s=(struct a *) malloc(len);*/ s->lk=ch; s->next=p; q->next=s; q=p=head;} else { printf("888 it is exist\n"); q=p=head;}
} printf("inserted:\n"); output(head); printf("plese input insert char:\n"); fflush(stdin);/*在此加上清流函数 */ scanf("%c",&ch); } return head;
}
main() {struct a *head,*p,*q,*s; int i; if((p=(a *)malloc(sizeof(a)))==NULL) exit(1); head=p; for(i=1;i<=25;i++) { (p->lk)=('a'+i-1); if((p->next=(a *)malloc(sizeof(a)))==NULL) exit(1); p=p->next;
} p->lk='z'; p->next=NULL; p=head; printf("26 char is :\n"); output(head); Deletechar(head); insert(head);
} 插入操作有问题,大家看看怎么改一下````谢谢了``` 删除一个字母后,在插就死循环`````