#include "stdlib.h"
#define datatype char
typedef struct node
{
datatype data;
struct node *next;
}Linknode,*Linklist;
{
Linknode *p,*q;
p=head;
char ch;
printf("单链表元素为单个字符,连续输入,按$结束输入:\n");
while((ch=getchar())!='$')
{
q=(Linklist)malloc(sizeof(Linknode));
q->data=ch;
q->next=NULL;
p->next=q;
p=q;
}
int countnode_head(Linknode *head)
{
int count;
Linknode *p;
p=head->next;
printf("%c",p->data);
p=p->next;
count=1;
while(p!=NULL)
{
printf("->%c",p->data);
p=p->next;
count++;
}
return count;
}
void main()
{
int countnode;
Linklist head;
head=(Linklist)malloc(sizeof(Linknode));
creat_node_rail(head);
countnode=countnode_head(head);
printf("\n节点数:%d\n",countnode);
}