#include<stdio.h>
#include<stdlib.h>
typedef struct node{ struct node *next; int data;
}node;
node *creatlist(int n)
{ node *head,*q,*p; int i; head=(node *)malloc(sizeof(node)); head->data=https://bbs.csdn.net/topics/1; p=head; for(i=2;i<=n;i++) { q=(node *)malloc(sizeof(node)); q->data=i; p->next=q; p=q; } p->next=head; return head;
}
int main()
{ int i=0,j; int n,m,a[n]; scanf("%d %d",&n,&m); node *head,*p,*q; head=creat(n); p=head; while(i<n) { for(j=1;j<m-1;j++) { p=p->next; } q=p->next; a[i]=q->data; p->next = q->next; free(q); p = p->next; i++; } for(i=0;i<n-1;i++) { printf("%d ",a[i]); } printf("%d",a[n-1]); return 0;
}
為什么會段錯誤,要修改哪里,求解

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/118702.html
標籤:C語言
下一篇:c語言大一鏈表一道題求助
