2018-02-07 12:09:44 +00:00
|
|
|
typedef struct Node{
|
2018-02-08 02:37:44 +00:00
|
|
|
unsigned long int id;
|
2018-02-07 12:09:44 +00:00
|
|
|
void *value;
|
2018-02-08 02:37:44 +00:00
|
|
|
struct Node *next;
|
|
|
|
struct Node *last;
|
|
|
|
}Node;
|
2018-02-07 12:09:44 +00:00
|
|
|
|
|
|
|
typedef struct List{
|
|
|
|
Node *head;
|
|
|
|
Node *tail;
|
|
|
|
unsigned long int length;
|
2018-02-08 02:37:44 +00:00
|
|
|
}List;
|
2018-02-07 12:09:44 +00:00
|
|
|
|
|
|
|
List *init_list();
|
|
|
|
Node *init_node();
|
|
|
|
int insertInHead(List *p_list, Node *p_node);
|
2018-02-07 15:28:28 +00:00
|
|
|
int insertInTail(List *p_list, Node *p_node);
|
2018-02-07 12:09:44 +00:00
|
|
|
int removeById(List *p_list, unsigned long id);
|
|
|
|
int removeByNode(List *p_list, Node *p_node);
|
|
|
|
int popFromHead(List *p_list);
|
|
|
|
int popFromTail(List *p_list);
|
|
|
|
unsigned long int len(List *p_list);
|
|
|
|
Node *findById(List *p_list, unsigned long int id);
|
|
|
|
Node *findByValue(List *p_list, char type[], void *value);
|
2018-02-07 15:28:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
int insertInHead(List *p_list, Node *p_node){
|
|
|
|
p_list->head->last = p_node;
|
|
|
|
//p_node->last = NULL;
|
|
|
|
p_node->next = p_list->head;
|
|
|
|
p_list->head = p_node;
|
2018-02-08 02:37:44 +00:00
|
|
|
return 0;
|
2018-02-07 15:28:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int insertInTail(List *p_list, Node *p_node){
|
|
|
|
p_list->tail->next = p_node;
|
|
|
|
//p_node->next = NULL;
|
|
|
|
p_node->last = p_list->tail;
|
|
|
|
p_list->tail = p_node;
|
2018-02-08 02:37:44 +00:00
|
|
|
return 0;
|
2018-02-07 15:28:28 +00:00
|
|
|
}
|