// 插入/查找/删除 int insert(dlist_ptr dlist, node_ptr pos, elem_type _data) { node_ptr start = dlist->head->next;//指向第一个有效节点 while( start && start != dlist->head && start != pos ){ start = start->next; } if(start && start != dlist->head && start == pos){ node_ptr tmp = buy_node(_data); if(tmp){ //1. 插入的节点是尾节点 if(pos == dlist->tail){ tmp->prev = dlist->tail; tmp->next = dlist->head; dlist->tail->next = tmp; dlist->head->prev = tmp; dlist->tail = tmp; }else{ //2. 插入的节点是正常节点 tmp->next = pos->next; tmp->prev = pos; pos->next->prev = tmp; pos->next = tmp; } return _TRUE_; } } return _FALSE_; }
int push_front(node_ptr head, elem_type _data) { node_ptr tmp = buy_node(_data); if(tmp){ tmp->next = head->next; head->next = tmp; return 0; } return 1; }
int init_list(node_pptr phead) { *phead = buy_node(0); if(*phead){ (*phead)->data = 0; (*phead)->next = *phead; return 0; } return 1; }
Node *create_thread_tree(const ElemType **str){ Node *s = NULL; if (**str != END){ s = buy_node(); s->data = **str; (*str)++; s->left->child = create_thread_tree(str); (*str)++; s->right->child = create_thread_tree(str); } return s; }
int push_back(dlist_ptr dlist, elem_type _data) { node_ptr tmp = buy_node(_data); if(tmp){ tmp->prev = dlist->tail; tmp->next = dlist->head; dlist->tail->next = tmp; dlist->tail = tmp; dlist->size++; return _TRUE_; } return _FALSE_; }
int push_back(node_ptr head, elem_type _data) { node_ptr tmp = buy_node(_data); if(tmp){ node_ptr curr = head; while(curr&& curr->next != head){ curr = curr->next; } tmp->next = curr->next; curr->next = tmp; return 0; } return 1; }
// 初始化 int init_dlist(dlist_ptr dlist) { int res = _FALSE_; node_ptr tmp = buy_node(0); if(tmp){ dlist->head = tmp; dlist->tail = tmp; dlist->size = 0; tmp->prev = tmp; tmp->next = tmp; res = _TRUE_; } return res; }
Boolean push_back(List *list, int value) { List_node *node = NULL; node = buy_node(); node->data = value; if(list->count != 0){ list->tail->next = node; list->tail = node; }else{ list->head = node; list->tail = node; } list->count++; return TRUE; }
Boolean push_front(List *list, int value) { List_node *node = NULL; List_node *tp = NULL; node = buy_node(); node->data = value; if(list->count != 0){ tp = list->head; list->head = node; node->next = tp; }else{ list->head = node; list->tail = node; } list->count++; return TRUE; }
Boolean push_back(Dlist *dlist, void *value) //链表尾部插入 { Dlist_node *node = NULL; if(dlist == NULL || value == NULL){ return FALSE; } node = buy_node(); node->data =value; if(dlist->count == ZERO){ dlist->head = dlist->tail = node; }else{ node->prev = dlist->tail; dlist->tail->next = node; dlist->tail = node; } dlist->count++; return TRUE; }
Boolean push_front(Dlist *dlist, void *value) //链表头部插入 { Dlist_node *node = NULL; if(dlist == NULL || value == NULL){ return FALSE; } node = buy_node(); node->data = value; if(dlist->count == ZERO){ //链表没有元素时 dlist->head = dlist->tail = node; }else{ node->next = dlist->head; dlist->head->prev = node; dlist->head = node; } dlist->count++; return TRUE; }
// 头插/头删/尾插/尾删 int push_front(dlist_ptr dlist, elem_type _data) { node_ptr tmp = buy_node(_data); if(tmp){ if( is_empty(dlist) ){ tmp->next = dlist->head; tmp->prev = dlist->head; dlist->head->next = tmp; dlist->head->prev = tmp; dlist->tail = tmp; dlist->size++; }else{ tmp->next = dlist->head->next; tmp->prev = dlist->head; dlist->head->next->prev = tmp; dlist->head->next = tmp; (dlist->size)++; } return _TRUE_; } return _FALSE_; }
Boolean insert_prev_node(Dlist *dlist, Dlist_node *node, void *value) //插入到指定节点的前边 { Dlist_node *p_node = NULL; if(dlist == NULL || node == NULL || value == NULL){ return FALSE; } p_node = buy_node(); p_node->data = value; //进行插入操作 p_node->next = node; p_node->prev = node->prev; if(node->prev == NULL){ //node为第一个节点 dlist->head = p_node; }else{ //node不是第一个节点 node->prev->next = p_node; } node->prev = p_node; dlist->count++; return TRUE; }