#include<stdio.h>
#include<mylist.h>
void list_tail_add(struct list_head *head,struct list_head *item)
{
if(head == NULL || item == NULL)
return;
head->prev->next = item;
item->prev = head->prev;
head->prev = item;
item->next = head;
}
void list_remove(struct list_head *item)
{
if(item == NULL)
return;
item->prev->next = item->next;
item->next->prev = item->prev;
}
struct list_head * list_first(struct list_head *head)
{
struct list_head *t;
if(head == NULL)
return NULL;
if((t = head->next) == head)
return NULL;
list_remove(t);
return t;
}
int list_is_empty(struct list_head *head)
{
if(head == NULL)
return 1;
if(head->next != head)
return 0;
return 1;
}
void list_insert_after(struct list_head *curr_item,struct list_head *insert_item)
{
if(curr_item == NULL || insert_item == NULL)
return;
insert_item->next = curr_item->next;
curr_item->next->prev = insert_item;
curr_item->next = insert_item;
insert_item->prev = curr_item;
}