Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct data
- {
- int d;
- struct data *next;
- };
- typedef struct data Node;
- void insertCopy(int x, int n, Node **lis)
- {
- int pos = 1;
- Node *p, *head;
- head = *lis;
- if (lis == NULL)
- {
- p = NULL;
- }
- else
- {
- //first node
- if ((head->d == x) && (pos % n == 0))
- {
- p = newnode();
- p->d = x;
- p->next = head;
- *lis = p;
- }
- }
- if (head->next != NULL)
- {
- pos = 2;
- while(head->next != NULL)
- {
- if ((head->next->d == x) && (pos % n == 0))
- {
- p = newnode();
- p->d = x;
- p->next = head->next;
- head->next = p;
- }
- else
- {
- head = head->next;
- }
- pos++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement