void MinHblt<T>::InOrder(HbltNode<T>* t) {
    if (t != NULL) {
        PostOrder(t->left_);
        MinHblt<T>::Visit_(t);
        PostOrder(t->right_);
    }
}
Esempio n. 2
0
void Test4(){
	//情况1:最长路径就在根节点所在的树中
	int arr1[] = {1,2,3,4,0,0,0,5,0,0,6,7,0,8,0,0,9};
	//情况2:最长路径在根节点所在的子树中
	int arr2[] = {1,2,3,4,0,0,5,0,6};
	Node_p root1 = CreateBinaryTree(arr1,sizeof(arr1)/sizeof(*arr1),0);
	
	Node_p root2 = CreateBinaryTree(arr2,sizeof(arr2)/sizeof(*arr2),0);
	cout<<GetMaxDistance(root1)<<endl;	//6
	cout<<GetMaxDistance(root2)<<endl;	//4
	
	PrevOrder(root1);
	InOrder(root1);
	PostOrder(root1);
	GetTreeMirror(root1);
	cout<<endl;
	PrevOrder(root1);
	InOrder(root1);
	PostOrder(root1);
	cout<<endl;
	PrevOrder(root2);
	InOrder(root2);
	PostOrder(root2);
	GetTreeMirror(root2);
	cout<<endl;
	PrevOrder(root2);
	InOrder(root2);
	PostOrder(root2);
}
Esempio n. 3
0
void PostOrder(BinTree tree){
	if (tree==NULL)
		return;
	PostOrder(tree->pLeft);
	PostOrder(tree->pRight);
	printf("%d ",tree->m_value);
}
/*主函数*/
int main() {
	int n;
	int data;
	int key;
	BinaryTree btree = NULL;
	BinaryTree f = NULL, p = NULL;
	scanf("%d", &n);
	//btree = (BinaryTree)malloc(sizeof(BinaryTree)*n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &data);
		InsertBST(btree, data);
	}
	preOrder(btree, printNode);//前序遍历递归实现
	printf("\n");
	InOrder(btree, printNode);//中序遍历递归实现
	printf("\n");
	PostOrder(btree, printNode);//后序遍历递归实现
	printf("\n");
	scanf("%d", &key);
	printf("%d\n", SearchBST(btree, key, f, p));//查找操作
	scanf("%d", &key);
	printf("%d\n", SearchBST(btree, key, f, p));//查找操作
	scanf("%d", &data);
	InsertBST(btree, data);
	preOrder(btree, printNode);//前序遍历递归实现
	printf("\n");
	InOrder(btree, printNode);//中序遍历递归实现
	printf("\n");
	PostOrder(btree, printNode);//后序遍历递归实现
	printf("\n");
	InOrderSecond(btree);//中序遍历非递归实现
	LevelOrder(btree);//层次遍历
	return 0;
}
Esempio n. 5
0
// 后续遍历递归 
void PostOrder(pBTNode pRoot)
{
	if (pRoot) {
		PostOrder(pRoot->_pLeft);
		PostOrder(pRoot->_pRight);
		printf("%c ", pRoot->_data);
	}
}
Esempio n. 6
0
void PostOrder(NodeTree* ApT) {

    if(ApT != NULL) {
        PostOrder(ApT->left);
        PostOrder(ApT->right);
        Visit(ApT->info);
    }
}
Esempio n. 7
0
void PostOrder(BinaryTreeNode<T> *t)
{// Postorder traversal of *t.
   if (t) {
      PostOrder(t->LeftChild);   // do left subtree
      PostOrder(t->RightChild);  // do right subtree
      Visit(t);                  // visit tree root
      }
}
Esempio n. 8
0
File: L4.cpp Progetto: Themiak/SDiZO
void Node::PostOrder(Node *a) {
	if (a != NULL)
	{
		PostOrder(a->left);
		PostOrder(a->right);
		std::cout << a->key << " ";
	}
};
/*Bianry Search Tree 后序遍历递归实现*/
void PostOrder(BinaryTree btree, Status(*visit)(BinaryTree)) {
	if (btree != NULL)
	{
		PostOrder(btree->lchild, visit);
		PostOrder(btree->rchild, visit);
		visit(btree);
	}
}
Esempio n. 10
0
void PostOrder(BTreeNode *bt){
    if (bt != NULL) {
        PostOrder(bt->lchild);
        PostOrder(bt->rchild);
        printf("%c",bt->data);
    }
    return;
}
void PostOrder(NODE *p)
{    if(p->left)
        PostOrder(p->left);
    if(p->right)
        PostOrder(p->right);
    if(p->score > nowscore)
        ++rank;
}
void PostOrder(int temp)
{
     if(!temp)
       return;
     PostOrder(T[temp].left);
     PostOrder(T[temp].right);
     printf("%d\n",T[temp].info);
}
Esempio n. 13
0
void  BinaryST<T>::PostOrder(BSTNode<T> *ptr)
{
	if (ptr == NULL)
		return;

	PostOrder(ptr->lC);
	PostOrder(ptr->rC);
	cout << ptr->data.key << "(" << ptr->data.val << ")" << " ";
}
Esempio n. 14
0
void  BinaryST<T>::PostOrder(BSTNode<T> *ptr)  {
	Item item;
	if(ptr == NULL)
		return;
	PostOrder(ptr->lC);
	PostOrder(ptr->rC);
	item = ptr->data;
	cout << item.key << "(" << item.val << ") ";
}
Esempio n. 15
0
//后续遍历
void PostOrder(BiTree T)
{
     if(T!=NULL)
     {
        PostOrder(T->lchild);
        PostOrder(T->rchild);
        Visit(T);
     }
}
Esempio n. 16
0
void BinarySearchTree<Key, Value>::PostOrder (BSTnode* subtree, Visit& visitor)
{
    if (subtree!=NULL)
    {
        PostOrder(subtree->m_left, visitor);
        PostOrder(subtree->m_right, visitor);
        visitor(subtree->m_value);
    }
}
void PostOrder(BiTree *bt)
{
	if (bt != NULL)
	{
		PostOrder(bt->lchild);
		PostOrder(bt->rchild);
		printf("%c", bt->data);
	}
}
Esempio n. 18
0
void PostOrder(treeNode* root)    // 후위 순회
{
  if(root!=NULL)
  {
    PostOrder(root->left);    // Left Node Move
    PostOrder(root->right);   // Right Node Move
    printf("%c  ",root->data);  // Data Read
  }
}                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
Esempio n. 19
0
void MultiMap::PostOrder(association* cur)
{
    if (cur == NULL)
        return;
    
    PostOrder(cur->m_left);
    PostOrder(cur->m_right);
    delete cur;
};
void PostOrder(Tree Root)		//POstOrder Traversal
{
	if (Root !=NULL)
	{
		PostOrder(Root->Left);
		PostOrder(Root->Right);
		printf("%c",Root->data);
	}
}
Esempio n. 21
0
void  PostOrder(BitTree root)  
/* 后序遍历二叉树,root为指向二叉树(或某一子树)根结点的指针*/
{
 if(root!=NULL)
 {
  PostOrder(root ->LChild); /*后序遍历左子树*/
  PostOrder(root ->RChild); /*后序遍历右子树*/
  Visit(root ->data);       /*访问根结点*/
 }
}
Esempio n. 22
0
void PostOrder(BTree *tree)
{
    if(tree==NULL)
        return;
    if(tree->lchild!=NULL)
        PostOrder(tree->lchild);
    if(tree->rchild!=NULL)
        PostOrder(tree->rchild);
    Operator(tree->data);
}
Esempio n. 23
0
void PostOrder(TreeNode* tree, 
     QueType& postQue)
// Post: postQue contains the tree items in postorder.
{
  if (tree != NULL)
  {
    PostOrder(tree->left, postQue);
    PostOrder(tree->right, postQue);
    postQue.Enqueue(tree->info);
  }
}
void PostOrder(struct node *head)
{
    struct node *pr;
    pr=head;
    if (pr!=NULL)
    {
        PostOrder(pr->lchild);
        PostOrder(pr->rchild);
        printf("%c",pr->data);
    }
}
Esempio n. 25
0
void PostOrder(bitree_t *root)
{
	if (NULL == root) return;
	
	PostOrder(root->lchild);
	
	PostOrder(root->rchild);
	
	printf("%c ", root->data);
	
	return;
}
Esempio n. 26
0
void PostOrder(NODE* root)
{

    if(root == NULL)
        return;

    PostOrder(root->left);

    PostOrder(root->right);

    printf("%d->",root->data);
}
Esempio n. 27
0
void main()
{
    int choice = 1 , number;
    int searchdata;
    int value;

    while(choice)
    {
        printf("\nEnter the number you want to insert\n");
        scanf("%d",&number);

        root = Insert(root,number);

        printf("\nDo you want to continue ?\n");
        scanf("%d",&choice);
    }

    printf("\nEnter the number you want to search\n");
    scanf("%d",&searchdata);

    value = Search(root,searchdata);

    if(value == 1)
        printf("\nThe value is found\n");
    else
        printf("\nThe value is not found\n");

    PostOrder(root);

}
int main()
{
	Tree T;
	printf("\t\t\t\tWelcome!!\n\tThis Program creates Expression tree For PostFix Equation\n\n");
	char equation[20];
    printf("Enter Expression:  ");
    scanf("%s",equation);
	printf("Your Entered Equation is\n");
	printf("\t\t\t\t%s\n",equation);
	if(PostfixCheck(equation)==1)			//Incase Equation is Valid
	{
		printf("\t\t\tIt is Valid PostFix Equation\n\tNow We can proceed further to build Exppress Tree for given equation\n\n\n");
		T=BulidTree(equation);				//Expression Tree Building Method is being called at this stage
		printf("\nInfix Equation by InOrder Traversal of Tree:\t\t");
		InOrder(T);
		printf("\nPostfix Equation by PostOrder Traversal of Tree:\t");
		PostOrder(T);
		printf("\nPrefix Equation by PreOrder Traversal of Tree:\t\t");
		PreOrder(T);
		printf("\n\t\t**********************************************\n\t\t\tThanks For Using Program\n\n");
	}
	else				//If Equation is Invalid, Program excuses to build expression Tree and stops
		printf("Equation is Invalid\nSorry!!!\n\t\tExpression Tree can't be built for Invalid Postfix Equation\n");
	return 0;
}
 bool DepthFirstOrder::check()
 {
     // check that post(v) is consistent with post()
       std::size_t r = 0;
        for (std::size_t v : PostOrder()) {
            if (Post(v) != r) {
                std::cout<<"post(v) and post() inconsistent"<<std::endl;
                return false;
            }
            r++;
        }

        // check that pre(v) is consistent with pre()
        r = 0;
        for (std::size_t v : PreOrder()) {
            if (Pre(v) != r) {
                std::cout<<"post(v) and post() inconsistent"<<std::endl;
                 return false;
            }
            r++;
        }


        return true;
    }
Esempio n. 30
0
int main()
{
    BTreeNode *bt;
    char *b;
    ElemtType x,*px;
    InitBTree(&bt);
    b = "c(a(d,e),b)";
    CreateBTree(&bt, b);
    /*
    if (bt != NULL) {
        printf("%c", bt->data);
    }
     */
    printf("preorder\n");
    PreOrder(bt);printf("\n");
    printf("inorder\n");
    InOrder(bt);printf("\n");
    printf("postorder\n");
    PostOrder(bt);printf("\n");
    printf("levelorder\n");
    LevelOrder(bt);printf("\n");
    printf("find one root\n");
    scanf("%c",&x);
    px = FindBTree(bt, x);
    if (px) {
        printf("find it !: %c\n",*px);
    }
    else{
        printf("not find it\n");
    }
    printf("the depth of bt is \n");
    printf("%d\n",BTreeDepth(bt));
    ClearBTree(&bt);
    return 0;
}