8_71.txt

来自「数据结构--C语言 数据结构源代码大全 用C语言编写」· 文本 代码 · 共 36 行

TXT
36
字号
int  InsertBST(BSTree  *bst,  KeyType  K)
/*若在二叉排序树中不存在关键字等于key的元素,插入该元素*/
{
	BSTree  f, q, s;
	s=(BSTree)malloc(sizeof(BSTNode));
	s->key = K;
	s->lchild = NULL;
	s->rchild = NULL;
	if ( *bst == NULL ) 
	{ 
		*bst = s; 
		return  1; 
	}
	f = NULL;
	q = *bst;
	while( q )
	{ 
		if ( q->key == K ) 
			return  0;
		if( K < q->key ) 
		{ 
			f = q; 
			q = q->lchild; 
		}
		else 
		{  
			f = q; 
			q = q->rchild; 
		}
	}
	if ( K < f->key ) 
		f->lchild = s; 
	else  
		f->rchild = s;
	return  1;  
}

⌨️ 快捷键说明

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