int main(int argc, char *argv[]) { AVLTree *pTree = NULL; AVLTreeNode *pSearch = NULL; int key = 0; AVLTreeNodeData eB = {9, "키 값이 9"}; AVLTreeNodeData eG = {3, "키 값이 3"}; AVLTreeNodeData eE = {1, "키 값이 1"}; AVLTreeNodeData eC = {10, "키 값이 10"}; AVLTreeNodeData eL = {12, "키 값이 12"}; AVLTreeNodeData eH = {6, "키 값이 6"}; AVLTreeNodeData eI = {4, "키 값이 4"}; AVLTreeNodeData eF = {5, "키 값이 5"}; pTree = createAVLTree(); if (pTree != NULL) { printf("1)\n"); insertNodeAVL(pTree, eB); displayAVLTree(pTree); printf("\n2)\n"); insertNodeAVL(pTree, eG); displayAVLTree(pTree); printf("\n3) LL 회전 발생\n"); insertNodeAVL(pTree, eE); displayAVLTree(pTree); printf("\n4)\n"); insertNodeAVL(pTree, eC); displayAVLTree(pTree); printf("\n5) RR 회전 발생\n"); insertNodeAVL(pTree, eL); displayAVLTree(pTree); printf("\n6) RL 회전 발생\n"); insertNodeAVL(pTree, eH); displayAVLTree(pTree); printf("\n7)\n"); insertNodeAVL(pTree, eI); displayAVLTree(pTree); printf("\n8) LR 회전 발생\n"); insertNodeAVL(pTree, eF); displayAVLTree(pTree); deleteAVLTree(pTree); } return 0; }
int main() { int i, option; Tree* BinarySearchTree = createEmptyTree(); TreeAVL* AVLTree = createEmptyAVLTree(); printf("Count and plot data\nBinary Search Tree vs. AVL Tree\n\n"); printf("To continue, type 1\nTo exit, type ant other key\n\n"); printf("Your option: "); scanf("%d", &option); if(option == 1) { for(i = 0; i < 10000; i++) { BinarySearchTree = insertNode(BinarySearchTree, i); AVLTree = insertNodeAVL(AVLTree, i); } printf("\nNumber of comparisons to find %d in the AVL Tree: %d\n", i - 1, binarySearchAVL(AVLTree, i - 1, 0)); printf("Number of comparisons to find %d in the Binary Search Tree: %d\n", i - 1, binarySearch(BinarySearchTree, i - 1, 0)); } return 0; }
int mainTree(){ int i; BinTree * tree = initBinTree(); if(tree->size == 0){ /* insertAsRoot(tree,16); insertAsLC(10,root(tree)); insertAsRC(25,root(tree)); insertAsLC(19,root(tree)->rc); insertAsRC(28,root(tree)->rc); insertAsLC(5,root(tree)->lc); insertAsRC(11,root(tree)->lc); //insertNode(tree,3); */ /*insertNode(tree,16); insertNode(tree,10); insertNode(tree,25); insertNode(tree,19); insertNode(tree,28); insertNode(tree,5); insertNode(tree,11); insertNode(tree,4); insertNode(tree,33); insertNodeAVL(36,tree); insertNodeAVL(38,tree); insertNodeAVL(39,tree); insertNodeAVL(40,tree); insertNodeAVL(41,tree); */ /* insertNodeAVL(3,tree); insertNodeAVL(5,tree); insertNodeAVL(11,tree); insertNodeAVL(16,tree); insertNodeAVL(19,tree); insertNodeAVL(25,tree); insertNodeAVL(28,tree); insertNodeAVL(33,tree); insertNodeAVL(36,tree); insertNodeAVL(39,tree); insertNodeAVL(41,tree); insertNodeAVL(43,tree); deleteBinNode(tree,28); deleteBinNode(tree,5); deleteBinNode(tree,25); deleteBinNode(tree,3); deleteBinNode(tree,33); */ for(i = 1 ; i < 10 ; i++){ insertNodeAVL(i,tree); } } if(tree->size!=0){ printf("根节点:%d \n" , root(tree)->data); printf("高度: %d\n",get_tree_height(root(tree))); printf("\n中序遍历---------------\n"); travIn_R(root(tree)); //printf("\n %d ",searchIn(root(tree),11)->data); //printf("\n %d ", getMax(root(tree))->data); //printf("\n %d ", getMin(root(tree))->data); printf("\n"); } for(i = 1 ;i < 8 ; i++) deleteBinNode(tree,i); //deleteNodeAVL(tree , i); if(tree->size!=0){ printf("根节点:%d \n" , root(tree)->data); printf("高度: %d\n",get_tree_height(root(tree))); printf("\n中序遍历---------------\n"); travIn_R(root(tree)); } /* if(tree->size == 0){ insertAsRoot(tree,'A'); insertAsLC('B',root(tree)); insertAsRC('E',root(tree)); insertAsRC('G',root(tree)->rc); insertAsLC('F',root(tree)->rc); insertAsLC('C',root(tree)->lc); insertAsRC('D',root(tree)->lc); } if(tree->size!=0){ printf("高度: %d\n",getTreeHeight(tree)); printf("高度: %d\n",get_tree_height(root(tree))); printf("节点数目:%d\n",getBinNodeSize(root(tree))); printf("前序遍历---------------\n"); travPre(root(tree)); printf("\n"); travPre_I1(root(tree)); printf("\n"); travPre_I2(root(tree)); printf("\n中序遍历---------------\n"); travIn_R(root(tree)); printf("\n"); travIn_I1(root(tree)); printf("\n层次遍历---------------\n"); traveLevel(root(tree)); printf("\n叶子节点数目 %d \n ",getLeafNum(root(tree))); //printf("\n%c",search(root(tree),'C')->data); } */ return 0; }