本文整理汇总了C++中destroy_node函数的典型用法代码示例。如果您正苦于以下问题:C++ destroy_node函数的具体用法?C++ destroy_node怎么用?C++ destroy_node使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了destroy_node函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: search_element
node_t* search_element(list_t *list, content_t element) {
node_t *cur = NULL;
node_t *_element = NULL;
if (list == NULL) {
printf("Initialize your list.");
return NULL;
}
if (list->size == 0) {
printf("No elements to search\n");
return NULL;
}
_element = create_node(element);
for (cur = list->head; cur != NULL; cur = cur->next) {
if (COMP(_element, cur) == 0) {
destroy_node(_element);
return cur;
}
}
destroy_node(_element);
return NULL;
}
示例2: sscanf
struct node *apply_bin_op(struct node *root, struct node *lhs, struct node *rhs)
{
long l, r;
char op, buf[25];
sscanf(lhs->token, "%ld", &l);
destroy_node(lhs);
sscanf(rhs->token, "%ld", &r);
destroy_node(rhs);
op = *root->token;
switch (op) {
case '+':
sprintf(buf, "%ld", l + r);
break;
case '-':
sprintf(buf, "%ld", l - r);
break;
case 't':
sprintf(buf, "%ld", l * r);
break;
}
destroy_node(root);
return create_node(buf, NUMBER);
}
示例3: destroy_node
void destroy_node( aabb_node* p )
{
if( !p ) { return; }
destroy_node( p->car );
destroy_node( p->cdr );
pool_.deallocate( p );
}
示例4: prune
/*Prune node 'n' from the tree rooted at 't->tree', rearranging the tree as
necessary in order to preserve the descendants of 'n'.*/
static void prune(btree *t, node *n)
{
register node **prune_site, *largest;
register int ref_count_of_largest;
prune_site = (n->parent==NULLTREE? &(t->tree): n==n->parent->left_child? &(n->parent->left_child): &(n->parent->right_child));
if(n->left_child == NULLTREE)
{
*prune_site = n->right_child;
if(*prune_site != NULLTREE)
(*prune_site)->parent = n->parent;
destroy_node(n);
}
else if(n->right_child == NULLTREE)
{
*prune_site = n->left_child;
if(*prune_site != NULLTREE)
(*prune_site)->parent = n->parent;
destroy_node(n);
}
else
{
/*find the largest value in the left subtree of 'n'*/
for(largest = n->left_child; largest->right_child != NULLTREE; largest = largest->right_child)
;
/*adjust reference counts to reflect the pruning of this largest value*/
ref_count_of_largest = largest->ref_count;
for(largest = n->left_child; largest->right_child != NULLTREE; largest = largest->right_child)
largest->subtree_ref_count -= ref_count_of_largest;
/*prune the largest value by replacing it with its left subtree*/
if(largest==largest->parent->left_child)
{
largest->parent->left_child = largest->left_child;
if(largest->parent->left_child != NULLTREE)
largest->parent->left_child->parent = largest->parent;
}
else
{
largest->parent->right_child = largest->left_child;
if(largest->parent->right_child != NULLTREE)
largest->parent->right_child->parent = largest->parent;
}
/*substitute this largest-valued node for node 'n'*/
if(n->parent == NULLTREE)
t->tree = largest;
else if(n == n->parent->left_child)
n->parent->left_child = largest;
else
n->parent->right_child = largest;
largest->parent = n->parent;
largest->left_child = n->left_child;
largest->right_child = n->right_child;
if(largest->left_child != NULLTREE)
largest->left_child->parent = largest;
if(largest->right_child != NULLTREE)
largest->right_child->parent = largest;
largest->subtree_ref_count = largest->ref_count + (largest->left_child==NULLTREE? 0: largest->left_child->subtree_ref_count) + (largest->right_child==NULLTREE? 0: largest->right_child->subtree_ref_count);
destroy_node(n);
}
}
示例5: destroy_node
void destroy_node(queue_head* qh) {
if (qh != NULL) {
destroy_node(qh->left_subtree);
destroy_node(qh->right_subtree);
free(qh);
}
}
示例6: destroy_node
// Recursively destroys the tree
static void destroy_node(art_node *n) {
// Break if null
if (!n) return;
// Special case leafs
if (IS_LEAF(n)) {
free(LEAF_RAW(n));
return;
}
// Handle each node type
int i;
union {
art_node4 *p1;
art_node16 *p2;
art_node48 *p3;
art_node256 *p4;
} p;
switch (n->type) {
case NODE4:
p.p1 = (art_node4*)n;
for (i=0;i<n->num_children;i++) {
destroy_node(p.p1->children[i]);
}
break;
case NODE16:
p.p2 = (art_node16*)n;
for (i=0;i<n->num_children;i++) {
destroy_node(p.p2->children[i]);
}
break;
case NODE48:
p.p3 = (art_node48*)n;
for (i=0;i<n->num_children;i++) {
destroy_node(p.p3->children[i]);
}
break;
case NODE256:
p.p4 = (art_node256*)n;
for (i=0;i<256;i++) {
if (p.p4->children[i])
destroy_node(p.p4->children[i]);
}
break;
default:
abort();
}
// Free ourself on the way up
free(n);
}
示例7: destroy_node
/* recursive freeing */
static void destroy_node(struct CBTree *tree, struct Node *node)
{
if (is_node(node)) {
destroy_node(tree, node->child[0]);
destroy_node(tree, node->child[1]);
cx_free(tree->cx, node);
} else if (tree->obj_free_cb) {
void *obj = get_external(node);
tree->obj_free_cb(tree->cb_ctx, obj);
}
}
示例8: destroy_node
void destroy_node(tnode_p node){
if(node->left != NULL) destroy_node(node->left);
if(node->right != NULL) destroy_node(node->right);
node->left = NULL;
node->right = NULL;
node->parent = NULL;
free(node->data);
node->data = NULL;
free(node);
}
示例9: destroy_nodes
void destroy_nodes(Node *node) {
// Recursively frees all the Nodes.
if(node != NULL) {
if(node->next == NULL)
destroy_node(node);
else {
destroy_nodes(node->next);
destroy_node(node);
}
}
}
示例10: destroy_chain
void destroy_chain(pnode *phead)
{
pnode ptmp = NULL;
if (*phead != NULL) {
while ((*phead)->next != *phead) {
ptmp = (*phead)->next;
(*phead)->next = ptmp->next;
ptmp->next->prev = *phead;
destroy_node(&ptmp);
}
destroy_node(phead);
}
}
示例11: destroy_channel
void destroy_channel(channel_t *channel) {
while (channel->subscribers->head != NULL) {
destroy_node(channel->subscribers, channel->subscribers->head);
}
free(channel->subscribers);
free(channel);
}
示例12: cbtree_destroy
/* Free tree and all it's internal nodes. */
void cbtree_destroy(struct CBTree *tree)
{
if (tree->root)
destroy_node(tree, tree->root);
tree->root = NULL;
cx_free(tree->cx, tree);
}
示例13: process_choice
int process_choice(tree *pTree, int choice)
{
char *words = (char *)Malloc(64*sizeof(char));
node *temp = NULL;
char ch = 'A';
switch(choice)
{
case ADD_NODE:
printf("Input the adding node content:\n");
while(scanf("%s", words) > 0)
{
//scanf("%s", words);
ch = getchar();
insert_node(pTree, words);
if(ch == '\n')
{
break;
}
words = (char *)Malloc(64*sizeof(char));
}
break;
case DELETE_NODE:
printf("Input the destroy node content\n");
while(scanf("%s", words) > 0)
{
//scanf("%s", words);
destroy_node(pTree, words);
ch = getchar();
if(ch == '\n')
{
break;
}
words = (char *)Malloc(64*sizeof(char));
}
break;
case FIND_NODE:
printf("Input the search node content\n");
scanf("%s", words);
temp = search_node_by_content( pTree, words);
break;
case SHOW_TREE:
print_tree(pTree);
break;
case QUIT:
print_tree(pTree);
printf("Nodes num:%d, row:%d\n", pTree->nodeNum, DEPTH);
exit(1);
break;
}
print_choice();
return 1;
}
示例14: main
int main(int argc, const char **argv)
{
struct dsp_node *node;
int ret = 0;
unsigned i;
signal(SIGINT, signal_handler);
#ifdef DEBUG
debug_level = 3;
#endif
ntimes = 1000;
argc--; argv++;
handle_options(&argc, &argv);
dsp_handle = dsp_open();
if (dsp_handle < 0) {
pr_err("dsp open failed");
return -1;
}
if (!dsp_attach(dsp_handle, 0, NULL, &proc)) {
pr_err("dsp attach failed");
ret = -1;
goto leave;
}
node = create_node();
if (!node) {
pr_err("dsp node creation failed");
ret = -1;
goto leave;
}
run_task(node, ntimes);
destroy_node(node);
leave:
if (proc) {
if (!dsp_detach(dsp_handle, proc)) {
pr_err("dsp detach failed");
ret = -1;
}
proc = NULL;
}
for (i = 0; i < ARRAY_SIZE(events); i++)
free(events[i]);
if (dsp_handle > 0) {
if (dsp_close(dsp_handle) < 0) {
pr_err("dsp close failed");
return -1;
}
}
return ret;
}
示例15: main
int main(void){
struct tree tr;
tr.root = NULL;
tr.cmpfunc = intcmpfunc;
insert_int(&tr, 15);
insert_int(&tr, 5);
insert_int(&tr, 3);
insert_int(&tr, 12);
insert_int(&tr, 10);
insert_int(&tr, 6);
insert_int(&tr, 7);
insert_int(&tr, 16);
insert_int(&tr, 20);
insert_int(&tr, 18);
insert_int(&tr, 23);
findthree(&tr);
traverse(tr.root, print_data);
print_successor(tr.root->left);
rb_delete(&tr, tr.root->left);
rb_delete(&tr, tr.root->left->right);
rb_delete(&tr, tr.root->left->left);
/*left_rotate(&tr, tr.root->right);
right_rotate(&tr, tr.root->right);*/
traverse(tr.root, print_data);
destroy_node(tr.root);
return 0;
}