tree_add.c

来自「Data Structure Ebook」· C语言 代码 · 共 32 行

C
32
字号
/* Binary tree implementation of a collection */static void AddToTree( Node *t, Node new ) {	Node base;	base = *t;	/* If it's a null tree, just add it here */	if ( base == NULL ) {		*t = new;		return;		}	else {		if ( KeyLess( ItemKey( new->item ), ItemKey( base->item ) ) )			{			AddToTree( &(base->left), new );			}		else			AddToTree( &(base->right), new );		}	}void AddToCollection( Collection c, void *item ) {	Node new, node_p;	assert( c != NULL );	assert( item != NULL );	/* Allocate space for a node for the new item */	new = (Node)malloc(sizeof(struct t_node));	/* Attach the item to the node */	new->item = item;	new->left = new->right = (Node)0;	AddToTree( &(c->node), new );	}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?