Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct ListNode {
- struct ListNode *next;
- struct ListNode *prev;
- void *value;
- } listnode_t;
- int main(int argc, char *argv[]){
- ...
- // Create two empty lists
- list_t *list1 = make_list();
- list_t *list2 = make_list();
- // Populate one with ints
- int x, y = 4, 5;
- list_push(list1, &x);
- list_push(list1, &y);
- // Populate other with strings
- string_t *str1 = make_string("foo");
- string_t *str2 = make_string("bar");
- list_push(list2, str1);
- list_push(list1, str2);
- ...
- // Delete at the end
- destroy_list(list1);
- destroy_list(list2);
- }
- void destroy_list(list_t *list)
- {
- listnode_t *cur = list -> first;
- for(cur = list -> first; cur != NULL; cur = cur -> next){
- if(cur -> prev){
- free(cur -> prev);
- }
- }
- free(list -> last);
- free(list);
- list = NULL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement