算法设计:
请设计一个算法,统计一个循环单链表L中的结点个数。
int n = 0;
while (L != NULL) { L = L->next; n++; }
/* counts the nodes in the list /
int fuc(struct list head)
{
void *tmp;
int i;
if(!head)
return -1;
for(i = 1, tmp = head, head = head->next; head != tmp; head = head->next)
i++;
return i;
}
count=0;
顺序遍历链表,遍历到一个节点count++