#include <stdio.h> #include <stdlib.h> typedef char Elemtype; typedef struct Lnode { Elemtype data; struct Lnode *next; }Lnode, *Linklist; void CreateList_head(Linklist *L1) { Lnode *p; int i; *L1=(Linklist)malloc(sizeof(Lnode)); (*L1)->next=NULL; for(i=0; i<26; i++) { p=(Lnode *)malloc(sizeof(Lnode)); p->data='A'+i; p->next=(*L1)->next; (*L1)->next=p; } } void CreateList_rear(Linklist *L2) { Lnode *p; Lnode *rear; int i; *L2=(Linklist)malloc(sizeof(Lnode)); (*L2)->next=NULL; rear=(*L2); for(i=0; i<26; i++) { p=(Lnode *)malloc(sizeof(Lnode)); p->data='A'+i; rear->next=p; rear=p; } rear->next = NULL; } void TraverseList(Linklist L) { Lnode *p; p=L->next; while(p) { printf("%c ", p->data); p=p->next; } printf("\n"); } int main() { Linklist L1, L2; CreateList_head(&L1); TraverseList(L1); CreateList_rear(&L2); TraverseList(L2); return 0; }

 

相关文章:

  • 2021-12-19
  • 2022-12-23
  • 2021-08-10
  • 2022-02-27
  • 2021-10-25
  • 2021-12-31
  • 2021-09-08
  • 2022-12-23
猜你喜欢
  • 2021-04-06
  • 2022-12-23
  • 2021-07-05
  • 2021-06-11
  • 2021-06-07
  • 2022-01-10
  • 2021-11-06
相关资源
相似解决方案