btree.cpp

来自「平衡二叉树操作的演示: 1、 操作界面给出查找、插入、删除、退出等操作选择。 」· C++ 代码 · 共 72 行

CPP
72
字号
// 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 + =
减小字号Ctrl + -
显示快捷键?