Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. typedef struct node *link;
  4.  
  5. struct node {int item; link next;};
  6.  
  7. int main(int argc, char*argv[])
  8. {
  9. int i = 0;
  10. int N = atoi(argv[1]);
  11. int M = atoi(argv[2]);
  12. link t = malloc(sizeof*t);
  13. link x = t;
  14. t -> item = 1;
  15. t -> next = t;
  16. printf("t:[%d]\n\n", t);
  17.  
  18. for(i = 2; i <= N; i++)
  19. {
  20.   x = (x->next = malloc(sizeof*x));
  21.   x -> item = i;
  22.   x -> next = t;
  23.   printf("x[%d], x->item[%d], x->next[%d]\n\n", x, x->item, x->next);
  24. }
  25. while( x != x->next)
  26. {
  27.   for(i = 1; i < M; i++)
  28.     x = x->next;
  29.     x->next = x->next->next;
  30.     printf("x[%d], x->item[%d], x->next[%d], x->next->next[%d]\n", x, x->item, x->next, x->next->next);
  31.     N--;
  32. }
  33. printf("%d\n", x-> item);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement