Skip to content

Instantly share code, notes, and snippets.

@amalloy
Created October 1, 2010 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amalloy/606693 to your computer and use it in GitHub Desktop.
Save amalloy/606693 to your computer and use it in GitHub Desktop.
struct person {
char *name;
struct person *next;
};
person *remove(person *list, char *name) {
if (list->name == name) return list->next;
person *prev = list;
person *curr;
while (curr = prev->next) {
if (curr->name == name) {
prev->next = curr->next;
return list;
}
}
}
int main() {
person *people = whatever;
people = remove(people, "david");
}
//OR==============
void remove(person **list, char *name) {
person *curr;
while (curr = *list) {
if (curr->name == name) {
*list = curr->next;
return;
}
list = &(*list)->next;
}
}
int main() {
person *people = whatever;
remove(&people, "david");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment