谁帮我做一下链表这道题
提示: 作者被禁止或删除 内容自动屏蔽
#include <stdio.h> #include <stdlib.h> typedef struct list { int num ; struct list *next ; }LIST ; int main(void) { LIST *head=NULL,*pre=NULL,*post=NULL, *start=NULL, *temp=NULL; long i, m, n, x; printf("n="); scanf("%ld",&n); printf("\nm="); scanf("%ld",&m) ; printf("\n"); if( n <= 1) { printf("1 "); return 0; } /**//*建立循环链表*/ pre = (LIST *)malloc(sizeof(LIST)); pre->num = 1 ; pre->next = NULL ; head = pre ; post = pre ; for(i=2 ; i<= n; i++) { pre = (LIST *)malloc(sizeof(LIST)); pre->num = i; pre->next= NULL ; post->next=pre ; post = pre ; } post -> next = head ; /**//*将最后一个结点的指向头,这样就构成了循不链表*/ pre= head ; i--; while(i>0) { printf(" %d ",pre->num); pre=pre->next; i--; } printf("\n"); printf("\n从第几个人开始:"); scanf("%d",&x); int count=n; while(count>0) { if(head->num==x) { pre=post; start=head; break; } if(pre->next->num==x) { start=pre->next; break; } pre=pre->next; count--; } if(count==0) { printf("\n 开始人错误\n"); system("pause"); exit(1); } while (start->next != start) { for(i=1; i < m ; i++) { pre = start ; start = start->next; } temp=start; start=start->next; pre->next=start; delete temp; } printf("last=%d \n",pre->num); return 0 ; }