问题描述
- 约瑟夫环代码错误,不知道哪里出了问题
- #include
using namespace std;typedef struct Node
{
int num;
int password;
struct Node *next;
}List;List *create(int n)
{
List *p *q *head;
int i = 1;
head = new List;
p = head;
cout<<""请输入第""< cin>>p->password ;
for(i = 2;i <= n;i++)
{
q = new List;
cout<<""请输入第""< cin>>q->password ;
p->next = q;
p = p->next ;
}
p->next = head;
return head;
}int output(List *L)
{
int m i;
List *p = L *q *s;
q = p;
cout<<""请输入m的初值""< cin>>m;
cout<<""出列顺序为:""< while(q != NULL)
{
for(i = 1; i {
q = p;
p = p->next ;
}
q->next = p->next;
cout<password < m = p->password;
q = p->next ;
delete(p);
}
return 0;
}int main()
{
List *L;
int n;
cout<<""请输入实验人数""< cin>>n;
L = create(n);
output(L);
return 0;
}