#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; }

 

posted on 2016-09-27 20:26  不忧尘世不忧心  阅读(1106)  评论(0编辑  收藏  举报