文件名称:N个人中一次叫第M个人出队
文件大小:2KB
文件格式:C
更新时间:2014-11-12 12:09:53
N个人中一次叫第M个人出队
#define NULL 0 #define LEN sizeof(linkqueue) #include "stdio.h" void clear() { //clrscr(); //gotoxy(16,5); //textcolor(0); } void good_bye() { clear(); printf("\n\n\n\t\t\t程序结束,再见!"); getchar(); } typedef struct node { int data; struct node *next; } linkqueue; linkqueue *creat_rcir(),*report_num(); int people,num; linkqueue *creat_rcir() { int i; linkqueue *head,*p,*rear; head=(struct node*)malloc(LEN); head->data=1; rear=head; for(i=2;i<=people;i++) { p=(struct node*)malloc(LEN); p->data=i; rear->next=p; rear=p; } rear->next=head; return(head); } linkqueue *report_num(head,m,people) linkqueue *head; int m,people; { linkqueue *p1,*p2; int max,j,count; max=people; printf("\n\n\t\t报数出列的顺序为:"); count=1;j=0; p1=head;p2=p1; do { p2=p1->next; count=count+1; if(count%m==0) { j++; printf("\n\t j=%2d\t no=%2d",j,p2->data); p1->next=p2->next; free(p2); } else p1=p2; } while(j!=max); head=NULL; printf("\n\n\t报数完毕再见!"); return(head); } void main() { linkqueue *hcir,*head; clear(); printf("\n\n\t\t请输入出列报数num="); scanf("%d",&num); printf("\n\n\t\t请输入循环队列总人数people="); scanf("%d",&people); hcir=creat_rcir(); head=report_num(hcir,num,people); }