Jurous
Jurous
采纳率100%
2020-05-26 15:25

有大佬帮忙解读一下这段代码的功能实现吗

已采纳

#include
#include
struct node {
int no;
struct node * next;
};

main( )
{   int i, k;  struct node *head, *p, *q;
    head = (struct node *)malloc(sizeof(struct node));
    head->no   = -1;
    head->next = head;
    for ( i=30; i>0; i-- )                     
    {   p = (struct node *)malloc(sizeof(struct node));
        p->next = head->next;  p->no   = i;  head->next = p;
    }
    printf("\nThe original circle is :");
    while ( p->next != head )            
        p = p->next;
    p->next = head->next;                     
    for ( i=0; i<15; i++ )
    {   for ( k=1 ; k<9 ; k++ )
         p = p->next;
        q = p->next;                
        p->next = q->next;         
        printf("%3d", q->no);   
        free(q);                             
    }
}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • caozhy 回答这么多问题就耍赖把我的积分一笔勾销了 10月前

    看上去好像是约瑟夫环的问题
    https://www.cnblogs.com/cmmdc/p/7216726.html

    点赞 评论 复制链接分享