解题思路:
注意事项:
参考代码:
#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 人评分
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:593 |
孤独的骑士 (C语言代码)浏览:1416 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:584 |
【计算两点间的距离】 (C语言代码)浏览:875 |
素数的个数 一直是超时浏览:698 |
采药 (C语言代码)浏览:960 |
C语言程序设计教程(第三版)课后习题6.7 (C语言代码)简单版浏览:837 |
交换Easy (C语言代码)浏览:1313 |
C二级辅导-进制转换 (C语言代码)正解浏览:855 |
多输入输出练习1 (C语言代码)浏览:1470 |