Last active
December 15, 2015 06:58
-
-
Save jiyeqian/5219663 to your computer and use it in GitHub Desktop.
remove the node from a list (http://coolshell.cn/articles/8990.html)
This file contains 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
void remove_if ( node **head, node **rear, remove_fn rm ) | |
{ | |
for ( node **curr = head; *curr; ) { | |
node *entry = *curr; | |
if ( rm ( entry ) ) { | |
*curr = entry->next; | |
if ( *curr ) { | |
(*curr)->previous = entry->previous; | |
} else { // the rear node removed | |
*rear = entry->previous; | |
} | |
free ( entry ); | |
} else { | |
curr = &entry->next; | |
} | |
} | |
} |
This file contains 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
// http://coolshell.cn/articles/8990.html | |
void remove_if ( node **head, remove_fn rm ) | |
{ | |
for ( node **curr = head; *curr; ) { | |
node *entry = *curr; | |
if ( rm ( entry ) ) { | |
*curr = entry->next; // remove | |
free ( entry ); | |
} else { | |
curr = &entry->next; // move | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
remove:
move: