Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. struct data
  2. {
  3. int d;
  4. struct data *next;
  5. };
  6. typedef struct data Node;
  7.  
  8. void insertCopy(int x, int n, Node **lis)
  9. {
  10. int pos = 1;
  11.  
  12. Node *p, *head;
  13.  
  14. head = *lis;
  15.  
  16. if (lis == NULL)
  17. {
  18. p = NULL;
  19. }
  20. else
  21. {
  22. //first node
  23. if ((head->d == x) && (pos % n == 0))
  24. {
  25. p = newnode();
  26. p->d = x;
  27. p->next = head;
  28. *lis = p;
  29. }
  30. }
  31.  
  32. if (head->next != NULL)
  33. {
  34. pos = 2;
  35.  
  36. while(head->next != NULL)
  37. {
  38. if ((head->next->d == x) && (pos % n == 0))
  39. {
  40. p = newnode();
  41. p->d = x;
  42. p->next = head->next;
  43. head->next = p;
  44. }
  45. else
  46. {
  47. head = head->next;
  48. }
  49. pos++;
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement