c语言链表的建立

来源:互联网 发布:淘宝货到付款好不好 编辑:程序博客网 时间:2024/05/16 23:56
#include "stdio.h"
#include "conio.h"

typedef struct LNode

{char data;
struct LNode *next;
}LNode,*LinkList;

LinkList createListR(void)
{char ch;
LinkList L=(LinkList)malloc(sizeof(LNode));
LNode *q,*r=L;
printf("please input data:");
while((ch=getchar())!='\n')
{q=(LNode*)malloc(sizeof(LNode));
q->data=ch;
r->next=q;r=q;
}
r->next=NULL;
return L;
}

int main(void)
{LinkList L,p;
L=createListR();
for(p=L->next;p!=NULL;p=p->next)
printf("%c",p->data);
getch();

}


“这只是我的一个小的开始,希望经过深入学习后,能够写出更大更实用的程序,加油吧!”

原创粉丝点击