void change( int n, int m, NODE * head )
{
int already_have[10000]={0};
int i,i_1,judge[10000]={0};
NODE *then,*go_on,*check;
go_on=head;
then=(NODE*)malloc(sizeof(NODE));
go_on->next=then;
then->data=n*10/m;
then->next=NULL;
go_on=then;
judge[0]=n;
for (already_have[0]=1,i=1,already_have[n]=1,n=n*10%m; already_have[n]!=1; already_have[n]=1,n=n*10%m,i++) {
judge[i]=n;
then=(NODE*)malloc(sizeof(NODE));
go_on->next=then;
then->data=n*10/m;
then->next=NULL;
go_on=then;
}
if (n!=0) {
for (i_1=0,check=head->next; check!=NULL; check=check->next,i_1++) {
if ((n)==judge[i_1]) {
break;
}
}
then->next=check;
}
}
NODE * find(NODE * head,int *n)
{
NODE *point[10000]={0};
NODE *p,*check;
int i,i_check,flag=0;
for (p=head->next,i=0; p!=NULL; p=p->next,i++) {
for (check=p,i_check=0; i_check<i; i_check++) {
if (check==point[i_check]) {
flag=1;
break;
}
}
if (flag==1) {
break;
}
point[i]=p;
}
if (flag==0) {
*n=0;
return NULL;
}
else{
*n=i-i_check;
return check;
}
}数据结构——求循环节
最新推荐文章于 2024-03-26 20:24:17 发布
该博客介绍了如何在链表中找到循环的起始节点。`change` 函数用于构造一个循环链表,`find` 函数则用于查找循环链表的入口节点。通过对链表遍历和记录节点,当遇到重复节点时确定循环并返回循环的入口。
423

被折叠的 条评论
为什么被折叠?



