Advertisement
Metalhead33

linkedl.h

May 30th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.04 KB | None | 0 0
  1. #ifndef LINKEDL_H
  2. #define LINKEDL_H
  3. #include <stdlib.h>
  4. /*Singly linked list*/
  5. #define SINGLE_LINKED_LIST(x,y) typedef struct t_##y { \
  6.     struct t_##y * next; \
  7.     x content; \
  8.     } y; \
  9.     y * y##_findLast(y * intro) { \
  10.     y * anchor; \
  11.     for(anchor=0;anchor.next;anchor = anchor.next); \
  12.     return anchor; \
  13.     }
  14.    
  15. /*Double linked list*/
  16. #define DOUBLE_LINKED_LIST(x,y) typedef struct t_##y { \
  17.     struct t_##y *prev; \
  18.     struct t_##y *next; \
  19.     x content; \
  20.     } y; \
  21.     y * y##_findLast(y * intro) { \
  22.     y * anchor; \
  23.     for(anchor=0;anchor->next;anchor = anchor->next); \
  24.     return anchor; \
  25.     } \
  26.     y * y##_findFirst(y * intro) { \
  27.     y * anchor; \
  28.     for(anchor=0;anchor->prev;anchor = anchor->prev); \
  29.     return anchor; \
  30.     }
  31.    
  32. /*Non-null terminated container */
  33. #define CONTAINER(x,y) typedef struct t_##y { \
  34.     x * content; \
  35.     size_t num; \
  36.     } y; \
  37.     y * y##_initialize(size_t size) { \
  38.     y * temp; \
  39.     temp = (y*)malloc(sizeof(y)); \
  40.     temp->num = size; \
  41.     temp->content = (x*)malloc(sizeof(x) * size); \
  42.     return temp; \
  43.     }
  44. #endif /* LINKEDL_H */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement