예제 #1
0
void Postorder(node *root) {
    
    if(root==NULL) return;
    Postorder(root->left);
    Postorder(root->right);
    printf("%d ", root->data);
}
void Postorder(node *root) {
    if (root == NULL) return;

    Postorder(root -> left);
    Postorder(root -> right);

    cout << root -> data << " ";
}
예제 #3
0
파일: Tree.cpp 프로젝트: samyak3/Algorithms
void Postorder(btNode* pRoot)
{
	if(pRoot == NULL)
		return;	
	Postorder(pRoot->left);
	Postorder(pRoot->right);
	cout<<pRoot->data<<"\t";
}
예제 #4
0
파일: AB_BAS1.C 프로젝트: h3nnn4n/main_ccs
/* Visita em Postorder */
   void Postorder(arv_bin * root )
   {
      if (root)
      {   Postorder(root->left);
         Postorder(root->right);
         printf("\n Pos-Ordem:: %s\t||\t %d" ,root->info, root->ordem);
      }
   }
예제 #5
0
파일: AVL.cpp 프로젝트: 1130310223/lab4
void Postorder(AVLTree tree)
{
    if(tree != NULL)
    {
        Postorder(tree->left);
        Postorder(tree->right);
        printf("%d ", tree->value);
    }
}
예제 #6
0
파일: packing.c 프로젝트: Zawicki/ECE368
void Postorder(Node * arr, int ind)
{
	if ((&arr[ind]) -> lc != -1)
		Postorder(arr, (&arr[ind]) -> lc);
	if ((&arr[ind]) -> rc != -1)
		Postorder(arr, (&arr[ind]) -> rc);
	
	printf("%d ", ind);
}
void Postorder(BSTNode * current)
{
    if(current!=NULL){

        Postorder(current->left);
        Postorder(current->right);
        std::cout << current->id << " " ;
    }
}
예제 #8
0
void BinaryTree::Postorder(Node* temp)
{
    if (temp!=NULL)
    {
        Postorder(temp->left);
        Postorder(temp->right);
        std::cout << temp->data << " ";
    }
}
예제 #9
0
//后序遍历(递归)
void Postorder(BiTree T)
{
    if(T)
    {
        Postorder(T->lch);
        Postorder(T->fright);
        printf("%c ",T->data);
    }
}
예제 #10
0
파일: creat_btree.c 프로젝트: Crabbit/c
//后序遍历 (递归)
void Postorder (struct BiNode *T)
{
     if(T) {
       Postorder(T->lch);
       Postorder(T->rch);
        
       printf(" %c",T->data); 
     }
} 
void Postorder(int *arr, int index)
{
  if(arr[index] == -1) {
    return ;
  }
  Postorder(arr, index*2 + 1);
  Postorder(arr, index*2 + 2);
  printf("%d ", arr[index]);
}
예제 #12
0
void Postorder(treeNode *node)
{
        if (node == NULL) {
                return;
        }

        Postorder(node -> left);
        Postorder(node -> right);
        printf("%d ", node -> data);
}
void Postorder(node *root) 
{   
    if (root==NULL) return;
    // Post Order traversal = Left-Right-Data
    
    // Recurse
    Postorder(root->left);
    Postorder(root->right);
    cout<<(root->data)<<" ";
    
}
예제 #14
0
	void Postorder(tree *root)
	{
		if(root)
		{
		Postorder(root->left);
		Postorder(root->right);
		printf("  %d  ",root->data);
		
		}
	return;
	}
예제 #15
0
void Postorder(node *root) {
    std::stack<node*> nodeStack;
    if(root != NULL){
        nodeStack.push(root);
    }
    Postorder(root->left);
    Postorder(root->right);
    while(!nodeStack.empty()){
        cout << nodeStack.top()->data << " ";
        nodeStack.pop();
    }
}
예제 #16
0
void Postorder(nodeT *p, int level)
{

	int i;
	if (p != NULL)
	{
		Postorder(p->left, level + 1);
		Postorder(p->right, level + 1);
		for (i = 0; i <= level; i++)
			printf(" "); /* for nice listing */
		printf("%d\n", p->data);
	}

}
예제 #17
0
int main()
{
        treeNode *root = NULL;
        root = Insert(root, 5);
        root = Insert(root, -1);
        root = Insert(root, 3);
        root = Insert(root, -14);
        root = Insert(root, 8);
        root = Insert(root, 10);
        root = Insert(root, 9);
        root = Insert(root, 6);

        printf("\nBefore Deletion BST in Inorder traversal\n ");
        Inorder(root);
        printf("\n\n");
        root = Delete(root,5);
        root = Delete(root,-1);

        printf("After Deletion BST\n");
        printf("\nInorder traversal\n");
        Inorder(root);
        printf("\nPreorder traversal\n");
        Preorder(root);
        printf("\nPostorder traversal\n");
        Postorder(root);

}
예제 #18
0
파일: creat_btree.c 프로젝트: Crabbit/c
int main()
{
    //建树 
    struct BiNode *T,*root;
    T = root;
    printf("The fuction Create() is called.\n");
    Create(T);
     
    //三种遍历递归算法 
    printf("\n");    
    printf("The fuction Preorder() is called.\n");
    Preorder(root);
     
    printf("\n");
    printf("The fuction Inorder() is called.\n");
    Inorder(root);
     
    printf("\n");
    printf("The fuction Postorder() is called.\n");
    Postorder(root);
     
     
    printf("\n");

    return 0;
}
예제 #19
0
파일: AVL.cpp 프로젝트: 1130310223/lab4
void Display(AVLTree root)
{
    printf("\n前序遍历: ");
    Preorder(root);
    printf("\n中序遍历: ");
    Inorder(root);
    printf("\n后序遍历: ");
    Postorder(root);
    printf("\n");
}
예제 #20
0
파일: reroot.c 프로젝트: Zawicki/ECE368
void Postorder(Node * h, double * x, double * y)
{
	if (h == NULL)
		return;

	Postorder(h -> lc, x, y);
	Postorder(h -> rc, x, y);
	if (h -> cut == 'V' || h -> cut == 'H')
		printf("%c", h -> cut);
	else
	{
		printf("(%le,%le)", h -> width, h-> height);
		if (*x == -1)
		{
			*x = h -> x;
			*y = h -> y;
		}
	}
}
// print the tree in preorder, inorder, and postorder form;
void print_tree(int *arr)
{
  printf("Preorder: ");
  Preorder(arr, 0);
  puts("");
  printf("Inorder: ");
  Inorder(arr, 0);
  puts("");
  printf("Postorder: ");
  Postorder(arr, 0);
  puts("");
}
예제 #22
0
파일: 1.cpp 프로젝트: 1130310223/lab4
void Display(AVLTree root)
{
    printf("\n== 前序遍历: ");
    Preorder(root);
    printf("\n== 中序遍历: ");
    Inorder(root);
    printf("\n== 后序遍历: ");
    Postorder(root);
    printf("\n");
    printf("== 高度: %d\n", AVLHeight(root));
    printf("== 最小值: %d\n", AVLMin(root)->value);
    printf("== 最大值: %d\n", AVLMax(root)->value);
}
예제 #23
0
파일: reroot.c 프로젝트: Zawicki/ECE368
int main (int argc, char * * argv)
{
	if (argc != 3)
	{
		printf("\nInvalid number of arguments\n");
		return EXIT_FAILURE;
	}

	char * in_file = argv[1];
	char * out_file = argv[2];

	// arr is an array implementation of a binary tree
	// the root node is the node of index num_n
	Node * head = Load_File(in_file);

	clock_t pack_t = clock();
	Find_Area(head);

	double x_new = 0;
	double y_prev = head -> height;

	Find_Coords(head, &x_new, &y_prev);
	pack_t = clock() - pack_t;	

	double x = -1;
	double y = -1;

	printf("\nPreorder: \n");
	Preorder(head);
	printf("\n\nInorder: \n");
	Inorder(head);
	printf("\n\nPostorder: \n");	
	Postorder(head, &x, &y);
	
	printf("\n\nWidth: %le\nHeight: %le\n", head -> width, head -> height);
	printf("\nX-coordinate: %le\nY-coordinate:%le\n", x, y);
	printf("\nElapsed Time:  %le\n\n", ((double) pack_t) / CLOCKS_PER_SEC);
	

	FILE * f = fopen(out_file, "w");
	Save_File(f, head);
	fclose(f);

	Tree_Destroy(head);

	return EXIT_SUCCESS;
}
예제 #24
0
파일: main.c 프로젝트: WangHuaJie/linux_whj
int
main(void)
{
	Bitree Root;
	Root = Build_Full_Bintree1(Get_Bintree_floors());
	Init_tree_data(Root);
	Preorder(Root);
	printf("\n");
	Inorder(Root);
	printf("\n");
	Postorder(Root);
	printf("\n");
	Unrecursive_Preorder(Root);
	Unrecursive_Inorder(Root);
	Unrecursive_Postorder(Root);
	Levelorder(Root);

	return 0;
}
예제 #25
0
int main()
{
    //建树
    printf("The function CreateTree() is called.\n");
    BiTree T;
    CreateTree(T);

    //三种遍历递归算法
    printf("\n");
    printf("The fuction Preorder() is called.\n");
    Preorder(T);

    printf("\n");
    printf("The fuction Inorder() is called.\n");
    Inorder(T);

    printf("\n");
    printf("The fuction Postorder() is called.\n");
    Postorder(T);


    printf("\n");
    system("pause");
}
예제 #26
0
파일: Tree.cpp 프로젝트: samyak3/Algorithms
int main()
{
	#if 1
	AddNode(&pRoot,4);
	AddNode(&pRoot,6);
	AddNode(&pRoot,2);
	AddNode(&pRoot,3);
	AddNode(&pRoot,5);
	AddNode(&pRoot,7);
	AddNode(&pRoot,1);
	
	//SubTree

	pRootSub = getbtNode(2);
	pRootSub->left = getbtNode(1);
	pRootSub->right = getbtNode(3);//true subtree case
	//pRootSub->right = getbtNode(4);//fasle subtree case
	#else//for Sum Tree 
	pRoot = getbtNode(30);
	pRoot->left = getbtNode(10);
	pRoot->right = getbtNode(5);
	pRoot->left->left = getbtNode(6);
	pRoot->left->right = getbtNode(4);
	pRoot->right->right = getbtNode(3);
	pRoot->right->left = getbtNode(2);
		
	#endif
	
	cout<<endl<<"##########################################################################################################"<<endl;
	
	cout<<"Inorder Traversal ::"<<endl;
	Inorder(pRoot);
	cout<<endl;
	
	cout<<endl<<"##########################################################################################################"<<endl;
	
	cout<<"Preorder Traversal ::"<<endl;
	
	Preorder(pRoot);
	cout<<endl;
	
	cout<<endl<<"##########################################################################################################"<<endl;
	
	cout<<"Postorder Traversal ::"<<endl;
	Postorder(pRoot);
	cout<<endl;
	
	cout<<endl<<"##########################################################################################################"<<endl;
	cout<<"Level Order Traversal ::"<<endl;
	LOrder(pRoot);
	cout<<endl;
	
	cout<<endl<<"##########################################################################################################"<<endl;
	cout<<"Size of the Tree ::"<<endl;
	cout<<GetTreeSize(pRoot);
	cout<<endl;
	
	cout<<endl<<"##########################################################################################################"<<endl;
	cout<<"Height of the Tree ::"<<endl;
	cout<<GetTreeHeight(pRoot);
	cout<<endl;
	
	cout<<endl<<"##########################################################################################################"<<endl;
	#if 0
	DeleteTree(&pRoot);
	
	AddNode(&pRoot,1);
	
	cout<<"Inorder Traversal after Deletion::"<<endl;
	Inorder(pRoot);
	cout<<endl;
	#endif
		
	MirrorTree(pRoot);	
	cout<<"Inorder Traversal after MirrorTree operation::"<<endl;
	Inorder(pRoot);
	cout<<endl;
	
	cout<<endl<<"##########################################################################################################"<<endl;
	
	MirrorTree(pRoot);
	cout<<"Inorder Traversal after MirrorTree operation for second time::"<<endl;
	Inorder(pRoot);
	cout<<endl;
	
	cout<<endl<<"##########################################################################################################"<<endl;
	cout<<"Max Element of the Tree ::"<<endl;
	cout<<MaxTreeElement(pRoot);
	cout<<endl;
	
	cout<<endl<<"##########################################################################################################"<<endl;
	
	int path[7];
	cout<<"Root To Leaf Paths ::"<<endl;
	RootToLeafPath(pRoot,path,0);
	cout<<endl<<"##########################################################################################################"<<endl;
	cout<<"Number of Leaf Nodes::"<<NumberOfLeafNodes(pRoot)<<endl;
	
	cout<<endl<<"##########################################################################################################"<<endl;
	
	cout<<"Ancestors of 7 are ::"<<endl;
	GetAncestors(pRoot,7);
	cout<<endl;

	cout<<endl<<"##########################################################################################################"<<endl;
	
	cout<<"CheckSumTree ::"<<IsSumTree(pRoot)<<endl;
	
	cout<<endl<<"##########################################################################################################"<<endl;
	
	cout<<endl<<"Lowest Common Ancestor of 1 and 3 ::"<<LCA(pRoot,1,3)->data<<endl;
	cout<<endl<<"Lowest Common Ancestor of 1 and 7 ::"<<LCA(pRoot,1,7)->data<<endl;
	cout<<endl<<"Lowest Common Ancestor of 4 and 6 ::"<<LCA(pRoot,4,6)->data<<endl;
	
	cout<<endl<<"##########################################################################################################"<<endl;
	cout<<endl<<"Tree has Path Sum 9 ::"<<hasPathSum(pRoot,9)<<endl;
	cout<<endl<<"Tree has Path Sum 100 ::"<<hasPathSum(pRoot,100)<<endl;
	cout<<endl<<"Tree has Path Sum 15 ::"<<hasPathSum(pRoot,15)<<endl;
	cout<<endl<<"##########################################################################################################"<<endl;
	
	cout<<endl<<"Subtree ::"<<IsSubTree(pRoot,pRootSub)<<endl;
	
	cout<<endl<<"##########################################################################################################"<<endl;
	return 0;
}
예제 #27
0
파일: packing.c 프로젝트: Zawicki/ECE368
Coord * Pack(Node * arr, int size, int num_b, double * x_tot, double * y_tot)
{
	Coord * crd = malloc(sizeof(Coord) * (num_b + 1));
	
	if (size == 1)
	{
		*x_tot = 0;
		*y_tot = 0;

		(&crd[1]) -> x = 0;
		(&crd[1]) -> y = 0;
	}

	printf("\nPreorder:  ");
	Preorder(arr, size);
	
	printf("\n\nInorder:  ");
	Inorder(arr, size);
	
	printf("\n\nPostorder:  ");
	Postorder(arr, size);

	double xt = 0;
	double max_h = 0;

	printf("\n\nCoords1: ");
	Find_Coords1(crd, arr, size, x_tot, &max_h);

	*y_tot += max_h;
	max_h = 0;

	printf("\n\nCoords2: ");
	Find_Coords2(crd, arr, size, &xt, &max_h, *y_tot);

	*y_tot += max_h;
	max_h = 0;
	if (xt > *x_tot)
		*x_tot = xt;
	xt = 0;

	printf("\n\nCoords3: ");
	Find_Coords3(crd, arr, size, &xt, &max_h, *y_tot);
	
	*y_tot += max_h;
	max_h = 0;
	if (xt > *x_tot)
		*x_tot = xt;
	xt = 0;

	printf("\n\nCoords4: ");
	Find_Coords4(crd, arr, size, &xt, &max_h, *y_tot);
	
	*y_tot += max_h;
	if (xt > *x_tot)
		*x_tot = xt;

	printf("\n\nWidth:  %le", *x_tot);
	printf("\nHeight:  %le", *y_tot);
	
	printf("\n\nX-coordinate:  %le", (&crd[num_b]) -> x);
	printf("\nY-coordinate:  %le", (&crd[num_b]) -> y);
	
	return crd;
}
예제 #28
0
/*		Main Function of Binary tree		*/
int main()
{
	int ch,f,data;
	tree *root;
	root=createTree();
	
	queue *Q;
	Q=create();
	
		    while(1){
	
	               printf("\n<1> Insert,  ");
	               printf("<2> Delete , ");
         	       printf("<3> PreOrder,  ");
	 	       printf("<4> InOrder, \n");
	 	       printf("<5> PostOrder,");
         	       printf("<6> Delete Tree");
         	       printf("<7> Height/Depth of tree, \n ");
         	       printf("<8> Maximum Node, ");
         	       printf("<9> Total Nodes Of Tree, ");
         	       printf("<10>LevelOrder traversal\n");
         	       printf("<0>Exit, Choice: ");
         	       scanf("%d",&ch);

		switch(ch){
			case 1:
				printf("\tNode Value :");
				scanf("%d",&data);
				
				Insert(&root,data);
				break;
			case 2:
				printf("\tNode To Delete :");
				scanf("%d",&data);
				f=Delete(&root,data);
				if(f)
				printf("Deleted Node:%d\n",f);
				break;		
			case 3:
				Preorder(root);
				break;
			case 4:
				Inorder(root);
				break;
			case 5:
				Postorder(root);
				break;
			case 6:
				DeleteTree(root);
				root=createTree();
				break;
			case 7:
				f=heightOfBinary(root);
			printf("\n(Non-recursive)Height/Depth OfBinary : %d\n",f);
		//		f=depthOfBinary(root);
		//	printf("(Recursive)Height/Depth OfBinary : %d\n",f);
				break;
				
			case 8:
				f=findMaxValue(root);
				printf("Maximum Value OfBinary : %d\n",f);
				break;
			case 9:
				f=sizeOfBinary(root);
				printf("Number of Nodes: %d\n",f);
				break;
			case 10:
				printf("\n");
				f=LevelOrderTraverse(root);
			printf("\n\nNumber of Nodes : %d\n",f);
			break;
			case 0:
				DeleteTree(root);
				 exit(0);
				 break;
			default :
			printf("\tInvalid Choice\n");
			}
		}
	}