shallowcmz


私信TA

用户名:shallowcmz

访问量:42343

签 名:

行者常至,为者常成

等  级
排  名 230
经  验 6207
参赛次数 1
文章发表 57
年  龄 18
在职情况 学生
学  校 东莞理工学院
专  业 软件工程

  自我简介:

解题思路:





注意事项:





参考代码:

#include <stdio.h>

#include <stdlib.h>

typedef struct Node

{

int num;

struct Node *next;

}node;

int size = sizeof(node);

int main(void)

{

node *phead = NULL, *p1, *p2 = NULL, *p3 = NULL;

int j, n, count, count1;

while (scanf("%d", &n) != EOF)

{

for (j = 1;j <= n;j++)

{

p1 = (node*)malloc(size);

p1->num = j;

p1->next = NULL;

if (j == 1)

phead = p1;

else

p2->next = p1;

p2 = p1;

}

//监督单位元

p1 = (node*)malloc(size);

p1->num = -1;

p1->next = NULL;

p2->next = p1;

p2->next->next = phead;


p3 = phead;

while (p3->next != phead)

p3 = p3->next;

p1 = phead;

count = n;

count1 = 0;

while (count != 2)

{

count1++;

if (count1 == 2)

{

count1 = 0;

count--;

printf("%d ", p1->num);

p3->next = p1->next;

p2 = p1;

p1 = p1->next;

if (p1->num == -1)

{

p3 = p1;

p1 = phead;

count1 = 0;

}

free(p2);

continue;

}

p3 = p1;

p1 = p1->next;

if (p1->num == -1)

{

p3 = p1;

p1 = phead;

count1 = 0;

}

}

printf("\n");

p1 = phead;

while (1)

{

if (p1->next->num == -1)

{

printf("%d\n", p1->num);

break;

}

else

printf("%d ", p1->num);

p1 = p1->next;

}

}

return 0;

}


 

0.0分

2 人评分

  评论区

  • «
  • »