#include <stdio.h>
struct Test
{
int data;
struct Test *next;
};
void printlink(struct Test *head)
{
struct Test *point;
point=head;
while(1)
{
if(point != NULL)
{
printf("%d ",point->data);
point=point->next;
}
else
{
putchar('\n');
break;
}
}
}
int getlinktotalnodenum(struct Test *head)
{
int cnt=0;
while(head != NULL)
{
cnt++;
head=head->next;
}
return cnt;
}
int main()
{
struct Test t1={1,NULL};
struct Test t2={2,NULL};
struct Test t3={3,NULL};
struct Test t4={4,NULL};
t1.next=&t2;
t2.next=&t3;
t3.next=&t4;
printlink(&t1);
int ret=getlinktotalnodenum(&t1);
printf("total num=%d\n",ret);
return 0;
}
运行结果:
——@上官可编程