#include<stdio.h>
#include <stdlib.h>
typedef struct Lnode{
char data;/*数据域,保存节点的值。*/
struct Lnode*next;/*指针域*/
} LNode;/*节点的类型*/
LNode *CreateList_L(int n);
void DispalyList(LNode*L);
void main(){
int i;
LNode *head;
printf("请输入单链表的长度:");
scanf("%d",&i);
getchar();
head=CreateList_L(i);
DispalyList(head);
}
LNode *CreateList_L(int n){
char ch;
int i;
LNode*head,*p ,*q;
head=(LNode*)malloc(sizeof(LNode));
head->next=NULL;
p=head;
for(i=1;i<=n;i++){
printf("创建第%d个节点\n",i);
scanf("%c",&ch);
getchar();
q=(LNode*)malloc(sizeof(LNode));
q->data=ch;
q->next=p->next;p->next=q;p=q;
}
return head;
}
void DispalyList(LNode*L){
LNode *p;
p=L;
p=p->next;
printf("该单链表中的数据元素是:");
while(p!=NULL){
printf("%c ",p->data);
p=p->next;
}
}