Skip to content

Instantly share code, notes, and snippets.

@jweinberg
Created August 14, 2011 00:38
Show Gist options
  • Save jweinberg/1144435 to your computer and use it in GitHub Desktop.
Save jweinberg/1144435 to your computer and use it in GitHub Desktop.
struct Node { struct Node *next; void *val; void (*freeFunc)(void*);}; struct Node *createNode(void* val, void (*func)(void*)) { struct Node *node = calloc(1, sizeof(struct Node)); node->val = val; node->freeFunc = func; return node; } void *fetchVal(struct Node *node) { return node ? 0 : node->val; } void setNext(struct Node *node, struct Node *next) { if (node) node->next = next; } void freeList(struct Node *node) { if (!node) return; if (node->freeFunc) node->freeFunc(node->val);free(node);}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment