解题思路:
注意事项:
参考代码:
#include <iostream>
using namespace std;
struct Node
{
int data;
Node* next, * prev;
}a[1001], * head, * tail;
int main()
{
int n; head = tail = NULL;
cin >> n;
for (int i = 1; i <= n; i++)
{
a[i].data = i;
if (head == NULL)
{
head = tail = &a[i];
}
else
{
tail->next = &a[i];
a[i].prev = tail;
tail = &a[i];
}
}
tail->next = head;
head->prev = tail;
Node* p = tail;
int count = 0;
while (1)
{
p = p->next;
++count;
if (count == 3)
{
if (p == p->next)
{
break;
}
Node* x = p->prev; Node* y = p->next;
x->next = y;
y->prev = x;
p = x;
count = 0;
}
}
cout << p->data;
return 0;
}
0.0分
1 人评分