?? jesoph.c
字號(hào):
#include <stdlib.h>struct node{ int number; struct node *next; };struct node *CreatList(int num){ int i; struct node *ptr1,*head; if((ptr1=(struct node *)malloc(sizeof(struct node)))==NULL) { perror("malloc"); return ptr1; } head=ptr1; ptr1->next=head; for(i=1;i<num;i++) { if((ptr1->next=(struct node *)malloc(sizeof(struct node)))==NULL) { perror("malloc"); ptr1->next=head; return head; } ptr1=ptr1->next; ptr1->next=head; } return head;}main(){ int n,m,k; printf("please input n\n"); scanf("%d", &n); printf("please input m\n"); scanf("%d", &m); printf("please input k\n"); scanf("%d", &k); int i; struct node *head,*ptr; head=CreatList(n); for(i=1;i<n+1;i++) { head->number=(i+k)%n; head=head->next; } i=1; while(head->next!=head) { if(i==m-1) { ptr=head->next; printf("number:%d\n",ptr->number); head->next=ptr->next; head=head->next; free(ptr); i=1; } else { head=head->next; i++; } } printf("number:%d\n",head->number); free(head); }
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -