#include <stdio.h>
#include <malloc.h>
#include <string.h>
typedef char datatype;
typedef struct node
{
datatype data;
struct node *next;
}linklist;
linklist *head,*p;
//建立链表
linklist *CREATLISTF()
{
char ch;
head = NULL; /*链表开始为空*/
ch = getchar(); /*读入第一个节点*/
while(ch !='$') /*逐个输入字符,以"-1"为结束的标志,返回头指针*/
{
p = (linklist*)malloc(sizeof(linklist)); /*生成新节点*/
p->data = ch; /*将输入的值放入数据域中*/
p->next = head;
head = p; /*将新节点插入到表头上*/
ch = getchar(); /*读入下一个节点*/
}
return head; /*返回头指针*/
} /*CREATLISTF*/
//输出链表
void print(linklist *head)
{
linklist *p;
p = head;
if(head != NULL)
do
{
printf("%s ",p->data);
p = p->next;
}while(p != NULL);
}
main()
{
linklist *start;
printf("Please input records: \n");
start = CREATLISTF();
printf("The records are :\n");
print(start);
}
[此贴子已经被作者于2006-4-13 23:26:18编辑过]