Last active
April 26, 2017 01:04
-
-
Save MattDiesel/1eb6167304f5e23b98c1fa9cd6346736 to your computer and use it in GitHub Desktop.
Delete multiples for prime sieve on linked list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node* Deletemultiples(node* head, int k) | |
{ | |
node* temp = head, *old = head, *todelete; | |
if (head == NULL) | |
return NULL; | |
while (temp!=NULL) { | |
if (temp->data % k ==0 && temp->data != k) { | |
todelete = temp; | |
if (temp == head) | |
head = temp->next; | |
else | |
old->next = temp->next; | |
temp = temp->next; | |
free(todelete); | |
} | |
else { | |
old = temp; | |
temp = temp->next; | |
} | |
} | |
return head; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment