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

54 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
/**
2019-01-12 00:54:05 +00:00
2018-12-21 09:36:57 +00:00
2019-01-12 00:54:05 +00:00
@param p_node
@return
2018-12-21 09:36:57 +00:00
*/
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;
return t_node;
}
2019-01-03 10:33:14 +00:00
/**
2019-01-12 00:54:05 +00:00
2019-01-03 10:33:14 +00:00
2019-01-12 00:54:05 +00:00
@param p_list
@return
2019-01-03 10:33:14 +00:00
*/
2018-08-23 16:57:38 +00:00
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;
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;
}