{
return list_entry(node->name.next, type, name); \
53
}
\
static
inline
bool
name##_is_last(struct
name##_head *head, const type *node) { \
return &head->_private == &node->name; \
} \
static
inline
void
name##_init(struct
name##_head *head) { \
INIT_LIST_HEAD(&head->_private); \
} \
\
static inline void name##_add_tail(struct
name##_head *head, type *new) { \
list_add_tail(&new->name, &head->_private); \
}
// ro’yxat elementini e’lon qilish
struct node {
struct list_head node_list;
char *string;
};
// berilgan nomda bog’langan ro’yxatni va
// element turini e’lon qilish
define_list(node_list, struct node);
struct node *new_node(const char *string)
{
struct node *ret = malloc(sizeof struct node);
ret->string = string;
return ret;
}
54
/* metod main */
int main(int argc, char *argv[])
{
// ro’yxatni yaratish va aniqlash
struct node_list_head head;
node_list_init(&head);
// ro’yxat oxiridan element qo’shish
node_list_add_tail(&head, new_node("1"));
node_list_add_tail(&head, new_node("2"));
node_list_add_tail(&head, new_node("3"));
Do'stlaringiz bilan baham: |