Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.92 KB | None | 0 0
  1. #ifndef __LINKEDLIST_H__
  2. #define __LINKEDLIST_H__
  3.  
  4. #include <stdbool.h>
  5.  
  6. /*
  7.  * The user of this class is responsible for cleaning up the memory used by any data used by this class
  8. */
  9.  
  10. struct llnode {
  11.     void* data;
  12.     struct llnode* next;
  13.     struct llnode* prev;
  14. };
  15.  
  16. struct linkedlist {
  17.     int size;
  18.     struct llnode* head;
  19.     struct llnode* tail;
  20. };
  21.  
  22. struct linkedlist linkedlist_create();
  23. // returns false if we cannot allocate memory for the internal linked list node
  24. bool linkedlist_insert(struct linkedlist* ll, void* data);
  25. // remove is a wrapper for removehead
  26. void* linkedlist_remove(struct linkedlist* ll);
  27. void* linkedlist_removetail(struct linkedlist* ll);
  28. void* linkedlist_removehead(struct linkedlist* ll);
  29. inline int linkedlist_getsize(struct linkedlist* ll);
  30. // calls memfree to free given data; memfree may be NULL
  31. void linkedlist_destroy(struct linkedlist* ll, void(*memfree)(void*));
  32.  
  33. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement