Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. typedef struct ListNode {
  2. struct ListNode *next;
  3. struct ListNode *prev;
  4. void *value;
  5. } listnode_t;
  6.  
  7. int main(int argc, char *argv[]){
  8. ...
  9. // Create two empty lists
  10. list_t *list1 = make_list();
  11. list_t *list2 = make_list();
  12.  
  13. // Populate one with ints
  14. int x, y = 4, 5;
  15. list_push(list1, &x);
  16. list_push(list1, &y);
  17.  
  18. // Populate other with strings
  19. string_t *str1 = make_string("foo");
  20. string_t *str2 = make_string("bar");
  21. list_push(list2, str1);
  22. list_push(list1, str2);
  23. ...
  24.  
  25. // Delete at the end
  26. destroy_list(list1);
  27. destroy_list(list2);
  28. }
  29.  
  30. void destroy_list(list_t *list)
  31. {
  32. listnode_t *cur = list -> first;
  33. for(cur = list -> first; cur != NULL; cur = cur -> next){
  34. if(cur -> prev){
  35. free(cur -> prev);
  36. }
  37. }
  38.  
  39. free(list -> last);
  40. free(list);
  41. list = NULL;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement