#include"stdio.h"
#include"stdlib.h"
typedef int elementype;
typedef struct link{
int data;
struct link *next;
}link,*linklist;
int main()
{
linklist l,p,q,s;
int a,j=0;
l=(linklist )malloc(sizeof(linklist));
l->next=l;
p=l;
while(1)
printf("請輸入連結串列資料:");
scanf("%d",&a);
if(a==0) break;
s=(linklist )malloc(sizeof(linklist));
s->data=a;
s->next=p->next;
p->next=s;
}
while(p->next!=l)
p=p->next;
j++;
printf("連結串列長度為:%d\n",j);
return 1;
#include"stdio.h"
#include"stdlib.h"
typedef int elementype;
typedef struct link{
int data;
struct link *next;
}link,*linklist;
int main()
{
linklist l,p,q,s;
int a,j=0;
l=(linklist )malloc(sizeof(linklist));
l->next=l;
p=l;
while(1)
{
printf("請輸入連結串列資料:");
scanf("%d",&a);
if(a==0) break;
s=(linklist )malloc(sizeof(linklist));
s->data=a;
s->next=p->next;
p->next=s;
}
p=l;
while(p->next!=l)
{
p=p->next;
j++;
}
printf("連結串列長度為:%d\n",j);
return 1;
}