#include<stdio.h>
typedef struct LNode
{
int data;
struct LNode *next;
}LNode,*LinkList;
int ListLength(LinkList L)
{
LinkList p=L;
int k=0;
while(p!=NULL)
{
k++;
p=p->next;
}
return k;
}
int main()
{
int n,i,a;
scanf("%d",&n);
LinkList p = new LNode;
LinkList L = p ;
for(i=1;i<=n;i++) //创建单链表
{
LinkList s=new LNode;
s->data=i;
p->next=s;
p=s;
}
p->next=NULL;
LinkList L1 = L->next;
while(L1)
{
printf("%d ",L1->data) ;
L1 = L1->next;
}
printf("\n");
a=ListLength(L->next);
printf("%d\n",a);
return 0;
}
转载于:https://www.cnblogs.com/NYNU-ACM/p/4237357.html