解题思路:
注意事项:
参考代码:
#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 人评分
P1001 (C++代码)浏览:819 |
C语言程序设计教程(第三版)课后习题6.2 (C语言代码)浏览:1429 |
C语言程序设计教程(第三版)课后习题5.7 (Java代码)浏览:906 |
wu-淘淘的名单 (C++代码)浏览:1523 |
DNA (C语言描述,数据结构)浏览:901 |
校门外的树 (C语言代码)浏览:728 |
核桃的数量 (C语言代码)浏览:719 |
1024题解浏览:873 |
1128题解(返回值为数组的情况)浏览:565 |
2^k进制数 (C语言描述,蓝桥杯)浏览:1452 |