急求c++高手帮我解释一下下面程序每一步都什么意思?

来源:百度知道 编辑:UC知道 时间:2024/05/22 16:05:37
谢了!每一步都说的什么,详细点
#include <iostream>

using namespace std;

const int people = 17;

struct outt
{
outt *next;
bool go;
int num;
};

int main( )
{
outt *p, *head;
int i, n = 0, t = 0;
head = new outt;
head->go = true;
head->num = 1;
p = head;
for ( i = 1; i < people; i++ )
{
outt *s = new outt;
p->next = s;
s->go = true;
s->num = i + 1;
p = s;
}
p->next = head;
p = head;
while ( n != people - 1 )
{
t++;
if ( t % 3 == 0 )
{
if ( p->go )
{
n++;
p->go = false;
}
else
t--;
}
p = p->next;
}
p = head;
while ( !p->go )
{
p = p->next;
}
cout << p->num;
return 0;
}

#include <iostream>

using namespace std;

const int people = 17;

struct outt //定义一个结构
{
outt *next; //定义一个数据成员(指针)
bool go; //逻辑型变量
int num; //整型变量
};

int main( )
{
outt *p, *head;
int i, n = 0, t = 0;
head = new outt;//申请动态空间
head->go = true; //第一个节点为真
head->num = 1; //...
p = head; //在表头插如结点
for ( i = 1; i < people; i++ ) //循环
{
outt *s = new outt; //申请动态空间
p->next = s;
s->go = true;
s->num = i + 1;
p = s;
}
p->next = head;
p = head;
while ( n != people - 1 )
{
t++;
if ( t % 3 == 0 )
{
if ( p->go )
{
n++;
p->go = false;
}
else
t--;
}
p = p->next;
}
p = head;
while ( !p->go )
{
p = p->next;
}
cout << p->num;
return 0;
}