ZE-Standard-Libraries/src/list/list_copy.c

55 lines
1.4 KiB
C
Raw Normal View History

2018-08-23 16:57:38 +00:00
#include <type.h>
#include <list/list.h>
2018-12-21 09:36:57 +00:00
/**
@param p_node
@return
*/
2018-08-23 16:57:38 +00:00
Node *copyNode(Node *p_node) {
Node *t_node = NULL;
2018-12-21 09:36:57 +00:00
//当开启ID模块的时候编译
2018-08-23 16:57:38 +00:00
#ifdef id_enable
if (p_node->s_id == NULL) t_node = initNode(0);
else t_node = initNode(p_node->s_id->deep);
t_node->s_id = copyS_id(p_node->s_id);
#endif
t_node->last = p_node->last;
t_node->next = p_node->next;
t_node->type = p_node->type;
t_node->value = p_node->value;
2018-12-21 09:36:57 +00:00
#ifdef list_quick_enable
2018-08-23 16:57:38 +00:00
t_node->f_number = p_node->f_number;
2018-12-21 09:36:57 +00:00
#endif
2018-08-23 16:57:38 +00:00
return t_node;
}
List *copyList(List *p_list) {
Node *p_node;
Node *t_node;
List *t_list = NULL;
#ifdef id_enable
if (p_list->s_id == NULL) t_list = initList(0);
else t_list = initList(p_list->s_id->deep);
#endif
t_list->head = p_list->head;
t_list->tail = p_list->tail;
#ifdef list_simple_h
t_list->s_id = p_list->s_id;
t_list->s_head = p_list->s_head;
t_list->s_tail = p_list->s_tail;
#endif
t_list->length = p_list->length;
if(p_list->head != NULL && p_list->tail != NULL){
p_node = p_list->head;
while (p_node != NULL) {
t_node = copyNode(p_node);
insertInTail(t_list, t_node);
p_node = p_node->next;
}
}
return t_list;
}