想初始化一个循环链表,但不知道问题出在哪里
#include <stdio.h>
#include <stdlib.h>
struct stu{
int data;
struct stu *next;
};
void setup(struct stu **pNode);
int main()
{
//printf("%d",Large);
struct stu *p,*h;
h=NULL;
setup(&h);
for(p=h;p->next!=h;p=p->next){
printf("%d\t",p->data);
}
return 0;
}
void setup(struct stu **pNode)
{
struct stu *r;
struct stu *temp;
int i;
printf("please in put the number \n");
printf("if i='0' quit\n");
while(1){
scanf("%d",&i);
if(0==i) return ;
if((*pNode)==NULL){
(*pNode)->data=i;
(*pNode)->next=*pNode;
}
else {
for(r=(*pNode);r->next!=(*pNode);r=r->next)
;//利用循环本身
temp=(struct stu*)malloc(sizeof(struct stu));
temp->data=i;
temp->next=(*pNode);
r->next=temp;
}
}
}