解题思路:
注意事项:
参考代码:
#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++代码)(都给答案了还算什么)浏览:972 |
C语言程序设计教程(第三版)课后习题10.1 (C语言代码)浏览:1435 |
兰顿蚂蚁 (C++代码)浏览:1091 |
【偶数求和】 (C语言代码)浏览:557 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:655 |
C语言程序设计教程(第三版)课后习题6.3 (C++代码)浏览:954 |
2004年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:503 |
C语言程序设计教程(第三版)课后习题6.8 (C语言代码)浏览:522 |
【计算两点间的距离】 (C语言代码)浏览:1482 |
sizeof的大作用 (C语言代码)浏览:1450 |