平衡二叉树(AVL)的插入和删除详解(上):http://blog.youkuaiyun.com/sysu_arui/article/details/7897017
1、测试代码
为减小篇幅,只给出了主程序,其他函数模块请看(上)中的描述。
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
AVL t ;
initAVL(t);
bool taller = false;
bool shorter = false;
int key;
string major;
ElementType e;
int choice = -1;
bool flag = true;
while(flag)
{
cout<<"--------------------"<<endl;
cout<<"0. print"<<endl
<<"1. insert"<<endl
<<"2. delete"<<endl
<<"3. search"<<endl
<<"4. exit"<<endl
<<"--------------------"<<endl
<<"please input your choice: ";
cin>>choice;
switch(choice)
{
case 0:
printAVL(t);
cout<<endl<<endl;
break;
case 1:

本文详细介绍了AVL树的插入和删除操作,包括测试代码和多个测试用例。首先,展示了如何进行元素的插入,插入完成后通过前序和中序遍历验证平衡二叉树的正确性。接着,演示了搜索操作和删除操作,并在每次操作后检查平衡二叉树的状态。通过一系列具体数值的插入、搜索和删除,帮助读者深入理解AVL树的运作机制。
最低0.47元/天 解锁文章
2104

被折叠的 条评论
为什么被折叠?



