⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 8-4.c

📁 这个是数据结构经典算法实现
💻 C
字号:
#include "stdio.h"
typedef int KeyType; /*假定关键字类型为整数*/
typedef struct node { /*结点类型*/
	KeyType key; /*关键字项*/
	/*其它数据域,InfoType视应用情况而定,下面不处理它*/
	struct node *lchild,*rchild;//左右孩子指针
} BSTNode;
typedef BSTNode * bitreptr; // bitreptr是二叉排序树的类型
int  Compare(int index1,int index2)
{
	if(index1>index2)
		return 1;
	else if(index1<index2)
		return -1;
	else 
		return 0;
}
bitreptr bst_insert(KeyType K,bitreptr t)
{
	bitreptr p;
	if(t==NULL) /*搜索不成功时插入新结点 */
	{ 
		p=(bitreptr)malloc(sizeof(BSTNode));
		p->key=K;
		p->lchild=NULL;
		p->rchild=NULL;
		return(p);
	}
	else 
		switch (Compare(t->key,K))
		{
			case 0:
				return(t); /*搜索成功时不插*/
			case 1: 
				t->lchild=bst_insert(K,t->lchild);/*在左子树上继续*/
				return(t); /*在左右子树上插入后返回原根指针*/
			case -1: 
				t->rchild=bst_insert(K,t->rchild);/*在右子树上继续*/
				return(t);
	}
}

void Initial(bitreptr R)
{
	//初始化
}
void main()
{
	bitreptr tree,result;
	KeyType inserted=10;
	Initial(tree);
	result=bst_insert(inserted,tree);	
}

⌨️ 快捷键说明

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