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

📄 btree.cpp

📁 平衡二叉树操作的演示: 1、 操作界面给出查找、插入、删除、退出等操作选择。 2、 每种操作均要提示输入关键字。 3、 每次插入或删除一个节点后
💻 CPP
字号:
// Btree.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "fun.h"
#include "stdlib.h"

int main()
{
	int i,key,flag=1,sign;BSTree T;BSTree p;ElemType e;int taller=FALSE;
	InitBSTree(T);//初始化树
	while(flag){
	system("cls");//清屏
	printf("\n选择你所要求的二叉平衡树的操作:");
	printf("\n0.退出。\n1.查找。\n2.插入。\n3.删除。\n");
	fflush(stdin);
	scanf("%d",&i);
	switch(i){
	case 0:flag=0;break;
	case 1:
		printf("\n输入你所要查找元素的关键字:");
		fflush(stdin);
		scanf("%d",&key);
		SearchBST(T,key,NULL,p);
		printf("\n\n平衡二叉树为:\n");
		Print_BSTree(T,1);
		printf("\n按任意键继续....");
		fflush(stdin);
		getchar();
		break;
	case 2:
		printf("\n输入你所要插入的元素值:");
		fflush(stdin);
		gets(e.ch);
		printf("\n输入你所要插入元素的关键字:");
		fflush(stdin);
		scanf("%d",&e.key);
		sign=InsertAVL(T,e,taller);
		if(sign)
			printf("\n插入元素成功!");
		else
			printf("\n插入元素失败!");
		printf("\n\n平衡二叉树为:\n");
		Print_BSTree(T,1);
		printf("\n按任意键继续....");
		fflush(stdin);
		getchar();
		break;
	case 3:
		printf("\n输入你要删除元素的关键字:");
		fflush(stdin);
		scanf("%d",&key);
		DelBNode(T,key);
		printf("\n\n平衡二叉树为:\n");
		Print_BSTree(T,1);
		printf("\n按任意键继续....");
		fflush(stdin);
		getchar();
		break;		
	default:
		printf("\n输入错误!");
		printf("\n按任意键继续....");
		fflush(stdin);
		getchar();
		break;
	}
	}

	return 0;
}

⌨️ 快捷键说明

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