解题思路:

注意事项:

参考代码:

#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 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区