5-3.c
来自「含有大量数据结构的源代码 请大家漫漫品味」· C语言 代码 · 共 37 行
C
37 行
#include <stdio.h>
#define N 10
typedef char datatype;
typedef struct node{
datatype data;
struct node *next;
} listnode;
typedef listnode *linklist;
listnode *p;
linklist creater()
{
char ch;
linklist head;
listnode *p,*r;
head=NULL;
r=NULL;/*r为尾指针*/
while((ch=getchar())!='\n'){
p=(listnode *)malloc(sizeof(listnode));
p->data=ch;
if(head=NULL)
head=p;/*head 指向第一个插入结点*/
else
r->next=p;/*插入到链表尾部*/
r=p;/*r指向最新结点,即最后结点*/
}
if (r!=NULL)
r->next=NULL;/*链表尾部结点的后继指针指定为空*/
return(head);
}
main()
{
linklist newlist=creater();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?