Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- typedef struct node *link;
- struct node {int item; link next;};
- int main(int argc, char*argv[])
- {
- int i = 0;
- int N = atoi(argv[1]);
- int M = atoi(argv[2]);
- link t = malloc(sizeof*t);
- link x = t;
- t -> item = 1;
- t -> next = t;
- printf("t:[%d]\n\n", t);
- for(i = 2; i <= N; i++)
- {
- x = (x->next = malloc(sizeof*x));
- x -> item = i;
- x -> next = t;
- printf("x[%d], x->item[%d], x->next[%d]\n\n", x, x->item, x->next);
- }
- while( x != x->next)
- {
- for(i = 1; i < M; i++)
- x = x->next;
- x->next = x->next->next;
- printf("x[%d], x->item[%d], x->next[%d], x->next->next[%d]\n", x, x->item, x->next, x->next->next);
- N--;
- }
- printf("%d\n", x-> item);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement