关于环链表的问题
各位大虾,我刚学不久单链表
现有个问题希望高手指教,急用
题目是这样的:
13人围成一圈,从第一个人开始顺序报号1、2、3.凡报到“3”者退出圈子,找到最后留在圈子中的人,输出他原来的序号
编程要求:使用环形链表。
#include<iostream>
using namespace std;
#define N 13
struct node{
int data;
node*next;
};
node*Huan_Creat()//建立(尾结点插入法形成环链)
{ node*head,*n,*tail;
int a,i=0;
head=NULL;
cout<<"请输入"<<N<<"个同学的编号:\n";
for(cin>>a;i<N;cin>>a,i++)
{ n=new node;
n->data=a;
if(!head)tail=head=n;
else tail->next=n,tail=n;
}
if(head)tail->next=head;
return head;
}
void Print(const node*head)//输出
{cout<<"链表上各结点的数据为:\n";
while(head)
{cout<<head->data<<'\t';
head=head->next;
}
cout<<'\n';
}
int delete_smnode(node*h)//删除指定结点
{node*p;
int m=0,y=0;
for(;m<N;m++)
{p=h;h=h->next;
if(m%3==0){delete p;y++;}//y是用来记录共有几个被删除的,以便于释放
}
return y;
}
void deletechain(node*h,int c)//释放
{node*p;
int r=0;
while(r<N-c)
{p=h;h=h->next;delete p;r++;}
}
int main()
{node*head;
int z;
head=Huan_Creat();
delete_smnode(head);
z=delete_smnode(head);
Print(head);
deletechain(head,z);
return 0;
}
调试不出来,这是咋回事啊