解题思路:
注意事项:
参考代码:
#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二级辅导-阶乘数列 (C语言代码)浏览:638 |
C语言程序设计教程(第三版)课后习题10.5 (C语言代码)浏览:761 |
C语言训练-排序问题<2> (C++代码)浏览:924 |
c primer plus 第十二章 12.1小节浏览:393 |
sizeof的大作用 (C语言代码)浏览:1566 |
简单的a+b (C语言代码)浏览:569 |
Tom数 (C语言代码)浏览:514 |
剪刀石头布 (C语言代码)浏览:1507 |
C语言训练-自守数问题 (C语言代码)浏览:786 |
1231题解(注意理解“输入多个测试实例”)浏览:826 |