WannaBe


私信TA

用户名:dotcpp0704046

访问量:96

签 名:

等  级
排  名 4801
经  验 1581
参赛次数 0
文章发表 3
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

TA的其他文章

C语言改版001
浏览:23

#include<stdio.h>

#include<stdlib.h>


typedef struct student{

    int number;

    struct student*next;

}node;


node *create(int n);

void function(node *head,int num);


int main()

{

    int n,m=3;

    node *head;

    scanf("%d",&n);

    

    head=create(n);

    function(head,m);

    

    return 0;

}


node* create(int n)

{

    node *head;

    head=(node*)malloc(sizeof(node));

    head->next=NULL;

    node *q=head;

    node *p;

    

    for(int i=1;i<=n;i++)

    {

        p=(node*)malloc(sizeof(node));

        p->number=i;

        p->next=q->next;

        q->next=p;

        q=p;

    }

    q->next=head->next;

    

    return head;

}


void function(node*t,int n)

{

    node*p=t->next;

    free(t);

    node*q=NULL;

    

    while(p->next !=p)

    {

        for(int i=1;i<=n-2;i++)

        {

            p=p->next;

        }

        

        q=p->next;

        p->next=q->next;

        

        p=p->next;   //移动到报号起点

        free(q);

    }

    printf("%d",p->number);

    return ;

}





 

0.0分

0 人评分

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

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区