| 
 | 
 
 
发表于 2018-10-11 23:15:50
|
显示全部楼层
 
 
 
 
这是哪门子的尾插法? - #include<stdlib.h>
 
 - #include<string.h>
 
 - #include <stdio.h>
 
 - #include <malloc.h>
 
  
- struct Book
 
 - {
 
 -     char a[20];
 
 -     struct Book *next;
 
 - };
 
  
- struct Book *initList(char *a)
 
 - {
 
 -     struct Book *p=(struct Book *)malloc(sizeof(struct Book));
 
 -     strcpy(p->a,a);
 
 -     p->next = NULL;
 
 -     return p;
 
 - }
 
  
- void append(struct Book *head, char *a)
 
 - {
 
 -     struct Book *p = head;
 
 -     struct Book *pNew = (struct Book *)malloc(sizeof(struct Book));
 
 -         while(p->next)
 
 -                 p = p->next;
 
 -         strcpy(pNew->a, a);
 
 -     pNew->next = p->next;
 
 -     p->next = pNew;
 
 - }
 
  
- void printList(struct Book *head)
 
 - {
 
 -     struct Book *p = head;
 
 -     while(p)
 
 -     {
 
 -         printf("%s",p->a);
 
 -         p = p->next;
 
 -     }
 
 - }
 
  
- int main(void)
 
 - {
 
 -     struct Book *p = initList("ABC");
 
 -     append(p,"DEF");
 
 -     append(p,"GHI");
 
 -     printList(p);
 
 -     return 0 ;
 
 - }
 
  复制代码 |   
 
 
 
 |