- C24zhengfujia's blog
h_h(链表)
- @ 2024-11-29 21:35:27
#include<cstdio>
struct node{
int cur;
int back;
node *next;
};
node *head,*p;
int n,temp,h_h;
int main()
{
scanf("%d",&n);
head=new node;
p=head;
for(int i=1;i<=n;++i)
{
scanf("%d",&temp);
p->next=new node;
p=p->next;
p->cur=i;
p->back=temp;
}
p->next=head->next;
p=p->next;
scanf("%d",&h_h);
while(p->cur!=h_h)
p=p->next;
for(int i=1;i<n;++i)
{
printf("%d ",p->cur);
temp=p->back;
if(temp==0)
break;
while(p->cur!=temp)
p=p->next;
}
printf("%d ",p->cur);
return 0;
}