#include <stdio.h> #include <stdlib.h> typedef struct node { int number; int mima; struct node * next; }Node, *Link; Link Init(void) { Link L; L = (Link)malloc(sizeof(Node)); L->next = L; return L; } void Insert(Link L, int e_mima, int e_number) { Link p,q; p = (Link)malloc(sizeof(Node)); p->mima = e_mima; p->number = e_number; q = L; while(q->next != L)q = q->next; p->next = q->next; q->next = p; } void Delete(Link L, int i) { Link p,q; q = L; while(q->next != q && q->next->number != i) q = q->next; if(q->next->number == i) { p = q->next; q->next = p->next; free(p); } } void main() { Link p,q,L; int i,m,n,mima; printf("intput the n,m "); scanf("%d%d",&n,&m); if(n<=0 || m<=0)return; L = Init(); i=1; while(i<=n) { printf("pass %d:",i); scanf("%d",&mima); if(mima <= 0)continue; Insert(L, mima, i); i++; } i = 0; p = L; while(L->next != L) { q = p; p = p->next; if(p ==L) { q = p; p = p->next; } i++; if(i == m) { printf("%d\t",p->number); m = p->mima; Delete(L, p->number); p = q; i = 0; } } getch(); }
|