#include"BinaryTree.h"
#include"BinarySearchTree.h"
#include"AVLTree.h"
#include<cstdlib>
int main()
{
//BinaryTree<int> bt1, bt2;
//bt1.creatBT();
//cout << "aaaaaaaaaaaaaaaa"<<endl;
//bt1.preOrderBT();
//cout << endl;
//bt1.inOrderBT();
//cout << endl;
//bt1.postOrderBT();
//cout << endl;
//bt1.outputBT();
//cout << "\nbt1 depth:" <<bt1.depthBT()
// << "\nbt1 number of node: "<< bt1.getNodeNumBT()
// << "\nbt1 number of leaf: "<< bt1.getLeafNumBT()
// << endl;
//cout << "aaaaaaaaaaaaaaaa"<<endl;
//bt2.getRootBT() = bt2.copyBT( bt1.getRootBT() );
//bt2.preOrderBT();
//cout << endl;
//bt2.outputBT();
//cout << "\ncompare bt1 & bt2: "<<endl;
//if( bt1.compareBT( bt2 ) )
// cout << "equal "<<endl;
//BinaryTree<int> bt;
//bt.creatBT();
//bt.preOrderBT();
//cout << endl;
//bt.inOrderBT();
//cout << endl;
//cout << "getOneEdgeNodeNumBT: " << bt.getOneEdgeNodeNumBT( bt.getRootBT() ) <<endl;
//cout << "getTwoEdgeNodeNumBT: "<< bt.getTwoEdgeNodeNumBT( bt.getRootBT() ) <<endl;
//cout << "withBT: " << bt.getMaxWithBT() <<endl;
//cout << "isCompleteBT: " << bt.isCompleteBT( bt.getRootBT() )<<endl;
//bt.swapChildBT( bt.getRootBT() );
//bt.preOrderBT();
//cout << endl;
//bt.inOrderBT();
//cout << endl;
//bt.deleteAllLeafBT( bt.getRootBT() );
//bt.preOrderBT();
//cout << endl;
//bt.inOrderBT();
//cout << endl;
int preArray[15] = { 14,9,5,3,2,7,12,28,18,17,50,30,60,53,63 };
int inArray[15] = { 2,3,5,7,9,12,14,17,18,28,30,50,53,60,63 };
//int postArray[15] = { 2,3,7,5,12,9,17,18,30,53,63,60,50,28,14 };
BinaryTree<int> bt1,bt2;
//bt1.creatBT();
//cout << "isCompleteBT: " << bt1.isCompleteBT( bt1.getRootBT() )<<endl;
//bt1.clearBT();
bt1.rebuildPreIn( preArray, inArray, 15, bt1.getRootBT() );
bt1.preOrderBT();
cout << endl;
bt1.inOrderBT();
cout << endl;
cout << "widthBT: " << bt1.findMaxWidthLevel() <<endl;
cout << "depthBT: " << bt1.depthBT() <<endl;
cout << "getLeafNumBT: " << bt1.getLeafNumBT() <<endl;
cout << "getOneEdgeNodeNumBT: " << bt1.getOneEdgeNodeNumBT( bt1.getRootBT() ) <<endl;
cout << "getTwoEdgeNodeNumBT: "<< bt1.getTwoEdgeNodeNumBT( bt1.getRootBT() ) <<endl;
cout << "isCompleteBT: " << bt1.isCompleteBT( bt1.getRootBT() )<<endl;
bt1.swapChildBT( bt1.getRootBT() );
cout << "swapChildBT(): "<<endl;
bt1.preOrderBT();
cout << endl;
bt1.inOrderBT();
cout << endl;
cout << "deleteAllLeafBT(): "<<endl;
bt1.deleteAllLeafBT( bt1.getRootBT() );
bt1.preOrderBT();
cout << endl;
bt1.inOrderBT();
cout << endl;
cout << "****************************************" <<endl;
BinarySearchTree<int> bst;
int iArray[10] = { 50, 72, 43, 85, 75, 20, 35, 45, 65, 30 };
for( int i = 0; i < 10; i++ ){
bst.insertBT( iArray[ i ], bst.getRootBT() );
}
bst.outputBT();
cout << endl;
bst.deleteBT( 72, bst.getRootBT() );
bst.outputBT();
cout << endl;
cout << "****************************************" <<endl;
AVLTree<int> a;
int iArray2[12] = { 20, 9, 2, 11, 13, 30, 22, 16, 17, 15, 18, 10 };
for( int i = 0; i < 12; i++){
a.insertBT( iArray2[ i ], a.getRootBT() );
//a.outputBT();
//cout << endl;
}
cout << endl;
a.deleteBT( 22, a.getRootBT() );
a.outputBT();
cout << endl;
a.deleteBT( 2, a.getRootBT() );
a.outputBT();
cout << endl;
a.deleteBT( 10, a.getRootBT() );
a.outputBT();
cout << endl;
a.deleteBT( 9, a.getRootBT() );
a.outputBT();
cout << endl;
system("pause");
}
评论2
最新资源