#include
#include
struct node {
int no;
struct node * next;
};
main( )
{ int i, k; struct node *head, *p, *q;
head = (struct node *)malloc(sizeof(struct node));
head->no = -1;
head->next = head;
for ( i=30; i>0; i-- )
{ p = (struct node *)malloc(sizeof(struct node));
p->next = head->next; p->no = i; head->next = p;
}
printf("\nThe original circle is :");
while ( p->next != head )
p = p->next;
p->next = head->next;
for ( i=0; i<15; i++ )
{ for ( k=1 ; k<9 ; k++ )
p = p->next;
q = p->next;
p->next = q->next;
printf("%3d", q->no);
free(q);
}
}