#include typedef struct _node { int data; struct _node *next; } node; node *createList ( unsigned int n ) { node *head, *p; unsigned int i; if (n == 0) return NULL; p = head = (node *)malloc(sizeof(node)); p -> data = 1; for (i=2; i<=n; ++i) { p -> next = (node *)malloc(sizeof(node)); p = p -> next; p -> data = i; } p -> next = head; return head; } void printList ( node *head ) { node *p; printf("[ "); if (head != NULL) { printf("%d ", head -> data); p = head -> next; while (p != head) { printf("%d ", p -> data); p = p -> next; } } printf("]\n"); } node *deleteCyclic ( node *head, unsigned int m ) { node *p, *q; unsigned int i; if (head == NULL) return NULL; p = head; while (p -> next != head) p = p -> next; while (p -> next != p) { for (i=0; i next; q = p -> next; p -> next = q -> next; if (q == head) head = q -> next; printf("Deleting %2d. ", q -> data); printList(head); free(q); } return head; } int main () { unsigned int n, m; node *head; printf("How many elements? "); scanf("%u",&n); printf("%u\n", n); head = createList(n); printf("Enter skip amount: "); scanf("%u", &m); printf("%u\n", m); printf("Initial list: "); printList(head); head = deleteCyclic(head,m); if (head != NULL) printf("Survivor = %d\n", head -> data); }