• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ postorder函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中postorder函数的典型用法代码示例。如果您正苦于以下问题:C++ postorder函数的具体用法?C++ postorder怎么用?C++ postorder使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了postorder函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: reset_edge_nums

void reset_edge_nums( PlacementTree& tree )
{
    // Edge numbers need to be in ascending order via postorder traversal.
    int current = 0;
    for( auto it : postorder(tree) ) {
        // The last iteration is skipped, as the root does not have an edge.
        if (it.is_last_iteration()) {
            continue;
        }

        it.edge().data<PlacementEdgeData>().reset_edge_num( current );
        ++current;
    }
}
开发者ID:lczech,项目名称:genesis,代码行数:14,代码来源:helper.cpp


示例2: main

int main(void)
{
    int n; scanf("%d", &n);
    int *a = malloc(sizeof(int) * n);
    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);
    if (judge(n, a, 0)) {
        puts("YES");
        tree_ptr h = NULL;
        for (int i = 0; i < n; i++)
            h = insert(h, a[i], 0);
        postorder(h, h);
    } else if (judge(n, a, 1)) {
        puts("YES");
        tree_ptr h = NULL;
        for (int i = 0; i < n; i++)
            h = insert(h, a[i], 1);
        postorder(h, h); 
    } else {
        puts("NO");
    }
    free(a);
}
开发者ID:yzyzsun,项目名称:fundamentals-of-data-structures,代码行数:23,代码来源:06-01.c


示例3: newicktree

void newicktree(int n,int* & P,int* & Suc1,int* & Suc2,string* & Labels,double* & B,string* & Support,FILE *w){
    list<int> post_order=postorder(P,Suc1,Suc2,n);
    int r=0;
    for (list<int>::iterator iter = post_order.begin();iter!=post_order.end();iter++){
        int i = *iter;
        int s1 = Suc1[i];
        int s2 = Suc2[i];
        ostringstream st1,st2;
        st1<< B[s1];
        st2<< B[s2];
        Labels[i]="("+Labels[s1]+Support[s1]+":"+st1.str()+","+Labels[s2]+Support[s2]+":"+st2.str()+")";
        r=i;
    }
    fprintf(w,"%s;\n",Labels[r].c_str());
}
开发者ID:jbloomlab,项目名称:phydms,代码行数:15,代码来源:utils.cpp


示例4: main

int main()
{
	struct node * root = newnode(1);
	root->left=newnode(2);
	root->right=newnode(3);
	root->left->left=newnode(4);
	root->left->right=newnode(5);
	printf("preorder\n");
	preorder(root);
	printf("INorder\n");
	inorder(root);
	printf("postorder\n");
	postorder(root);
	return 0;
}
开发者ID:Farheen2302,项目名称:Algorithms,代码行数:15,代码来源:Tree_traversal.c


示例5: main

int main(void)
{
	struct node* root = NULL;
	//struct node* root2 = NULL;
	struct node *find = NULL;

	char str[1024];

	root = insert(root, 10);
	root = insert(root, 15);
	root = insert(root, 9);
	root = insert(root, 8);
	root = insert(root, 13);
	root = insert(root, 7);
	root = insert(root, 5);
	root = insert(root, 18);
	root = insert(root, 22);
	root = insert(root, 3);
	root = insert(root, 4);
	root = insert(root, 2);
	root = insert(root, 1);
	print_ascii_tree(root);
	find = search(root, 18);
	print_ascii_tree(root);
	find = search(root, 22);
	printf("\n\n\nDATA found is %d\n", find->data);
	find = min_node(root);
	printf("Min in this tree is %d\n", find->data);
	find = max_node(root);
	printf("Mx in this tree is %d\n", find->data);
	print_ascii_tree(root);
	preorder(root);
	printf("\n");
	inorder(root);
	printf("\n");
	postorder(root);
	printf("\n");
	printf("DEPTH is %d\n", depth(root));
	tree_to_string(root, str);
	printf("The STR generated is %s\n", str);
	//string_to_tree(&root2, str);
	//print_ascii_tree(root2);
	printf("COUNT is %d\n",nodes(root));
	bool res = hassum(root, 45);
	printf("Bool val is %d\n", (int)res);
	levelorder(root);
	return 0;
}
开发者ID:abhimanyu12,项目名称:binary_trees,代码行数:48,代码来源:bin_tree.c


示例6: main

main()
{
	int choice,num;
	root=NULL;
	while(1)
	{
		printf("\n");
		printf("1.Insert\n");
		printf("2.Delete\n");
		printf("3.Inorder Traversal\n");
		printf("4.Preorder Traversal\n");
		printf("5.Postorder Traversal\n");
		printf("6.Display\n");
		printf("7.Quit\n");
		printf("Enter your choice : ");
		scanf("%d",&choice);

		switch(choice)
		{
		 case 1:
			printf("Enter the number to be inserted : ");
			scanf("%d",&num);
			insert(num);
			break;
		 case 2:
			printf("Enter the number to be deleted : ");
			scanf("%d",&num);
			del(num);
			break;
		 case 3:
			inorder(root);
			break;
		 case 4:
			preorder(root);
			break;
		 case 5:
			postorder(root);
			break;
		 case 6:
			display(root,1);
			break;
		 case 7:
			exit();
		 default:
			printf("Wrong choice\n");
		}/*End of switch */
	}/*End of while */
}/*End of main()*/
开发者ID:b-rajarshi,项目名称:code_ol_judges,代码行数:48,代码来源:BST.C


示例7: main

int main()
{
	int n;
	scanf("%d",&n);
	int i;
	struct node* root=NULL;
	for(i=0;i<n;i++)
	{
		int a;
		scanf("%d",&a);
		insert(&root,a,NULL);
	}
	inorder(root);
	printf("\n");
	preorder(root);
	printf("\n");
	postorder(root);
	printf("\n");
	int search;
	scanf("%d",&search);
	int start=0;
	int end=k-1;
	while(start<=end)
	{
		if(arr[start]+arr[end]==search)
		{
			printf("%d %d",arr[start],arr[end]);
			break;
		}
		else if(arr[start]+arr[end]>search)
		{
			end--;
		}
		else
		{
			start++;
		}
	}
/*	searchi(root,search);
	//printf("%d",root->right->left->data);
	inorder(root);
	printf("\n");
	preorder(root);
	printf("\n");
	postorder(root);
	printf("\n");*/
	return 0;
}
开发者ID:Bminus,项目名称:Algorithms,代码行数:48,代码来源:5.c


示例8: main

int main() 
{ 
	int n,x; 
	struct node *location,*parent; 
	do 
	{ 
		printf("1.insertion\n2.deletion\n3.search\n4.inorder traversal\n5.preorder traversal\n6.postorder\n7.exit\n"); 
		printf("\nenter ur choice\n"); 
		scanf("%d",&n); 
		switch(n) 
		{ 
			case 1: 
				printf("\nenter element to be inserted\n"); 
				scanf("%d",&x); 
				insert(x); 
				break; 
			case 2: 
				printf("\nenter element to be deleted\n"); 
				scanf("%d",&x); 
				del(x); 
				break; 
			case 3: 
				printf("\nenter element to be searched\n"); 
				scanf("%d",&x); 
				find(x,&parent,&location); 
				if(location!=NULL) 
				printf("\nsearch successfull\n"); 
				else 
				printf("\nitem not found\n"); 
				break; 
			case 4: 
				inorder(root); 
				break; 
			case 5: 
				preorder(root); 
				break; 
			case 6: 
				postorder(root); 
				break; 
			case 7: 
				return 0; 
				break; 
			default : 
				printf("\ndefault entry\n"); 
		} 
	} 
	while(n!=7); 
} 
开发者ID:jithesh92,项目名称:Btech-Labs,代码行数:48,代码来源:bst.c


示例9: main

void main()
{
	tnode *r;
	int n=0;
	char pre[max],in[max];
	printf("input inorder and postorder!  \n");
	gets(pre);
	gets(in);
	mktree(pre,0,strlen(pre)-1,in,0,strlen(in)-1,&r);
	printf("The preorder is as follows  \n");
	postorder(r);
	printf("\n There are %5d leaves in the tree. \n", leaf(r));
	printf("\nThe one degree node is as follows:\n");
	oneleaf(r,&n);
	printf("\n The one degree nodes number is:%d\n",n);
}
开发者ID:cqiyi,项目名称:kaoshi,代码行数:16,代码来源:exam010.cpp


示例10: show

show(NodeT *root,int level)
{
    while ('\n' != getc(stdin));
    printf( "\nPreorder listing\n" );
    preorder( root, 0 );
    printf( "Press Enter to continue." );
    while ('\n' != getc(stdin));
    printf( "\nInorder listing\n" );
    inorder( root, 0 );
    printf( "Press Enter to continue." );
    while ('\n' != getc(stdin));
    printf( "\nPostorder listing\n" );
    postorder( root, 0 );
    printf( "Press Enter to continue." );
    while ('\n' != getc(stdin));
}
开发者ID:kakas4,项目名称:C_programming,代码行数:16,代码来源:main.c


示例11: main

int main(int argc, char *argv[])
{
int array[] = {2, 3, 4, 5, 6, 8, 10, 12, 14, 15, 16, 18, 20};
int lb = 0;
int ub = sizeof(array)/sizeof(int) - 1;
tnode *root = tnode_construct_bst(array, lb, ub); 
preorder(root);
//Question
printf("\n");
postorder(root);
// Question
printf("\n");
tnode_destroy_bst(root);
// Question
return EXIT_SUCCESS;
}
开发者ID:jyshi,项目名称:ece264,代码行数:16,代码来源:exam2.c


示例12: TEST_F

TEST_F(SolutionTest, case1) {
	TreeNode *root = new TreeNode(1);
	root->left = new TreeNode(2);
	root->right = new TreeNode(3);
	root->left->left = new TreeNode(4);
	root->left->right = new TreeNode(5);
	root->right->left = new TreeNode(6);
	root->right->right = new TreeNode(7);

	int in[] = {4, 2, 5, 1, 6, 3, 7};
	int post[] = {4, 5, 2, 6, 7, 3, 1};
	vector<int> inorder(in, in + sizeof(in)/sizeof(int));
	vector<int> postorder(post, post + sizeof(post)/sizeof(int));
	TreeNode *node = solution_.buildTree(inorder, postorder);
	EXPECT_TRUE(solution_.isSameTree(root, node));
}
开发者ID:babypuma,项目名称:leetcode,代码行数:16,代码来源:construct_binary_tree_from_inorder_and_postorder_traversal_test.cpp


示例13: initialize

/**************************************************
 * This function opens the file and reads each    *
 * line into the buildArray function. It then     *
 * calls the rest of the functions to sort the    *
 * array and build the balanced binary tree.      *
 * EXIT 2 for file input error                    *
 * EXIT 1 for memory error                        *
 **************************************************/
void initialize(char *filename)
{
    FILE *fp;
    char buffer[21], **names;
    int count = 0, *count_ptr = &count, size = 2, *size_ptr = &size;
    BNODE* root;

    if ((fp = fopen(filename, "r")) == NULL)
    {
        printf("Error: Filename does not exist\n");
        exit(2);
    }
    
    if ((names = malloc(2 * sizeof(char*))) == NULL)
    {
        printf("Error: Unable to allocate memory\n");
        exit(1);
    }

    while (fgets(buffer, sizeof(buffer), fp) != NULL)
    {
        /* Double the size of the array after it is full */
        if (count == size)
            names = resizeArray(names, size_ptr);

        names = buildArray(names, buffer, count_ptr);
    }

    fclose(fp);

    names = sortArray(names, count_ptr);

    root = buildTree(names, 0, count-1);

    printf("\n preorder: ");
    preorder(root);
    printf("\n\n");

    printf("  inorder: ");
    inorder(root);
    printf("\n\n");

    printf("postorder: ");
    postorder(root);
    printf("\n");
}
开发者ID:rghamilton3,项目名称:c_programs,代码行数:54,代码来源:binaryTree-lib.c


示例14: main

/* Driver program to test above functions*/
int main()
{
     struct node *root  = newNode(1);
     root->left             = newNode(2);
     root->right           = newNode(3);
     root->left->left     = newNode(4);
     root->left->right   = newNode(5); 
 
     printf("\nPostorder traversal of binary tree is \n");
     postorder(root);
 
     printf("\nPostorder traversal using iterative approach\n");
     postorder_iterative(root);
 
     getchar();
     return 0;
}
开发者ID:sriladda,项目名称:practice,代码行数:18,代码来源:postorder.c


示例15: postorder

void postorder (astree* root) {
   assert (root != NULL);
   if (root->symbol == TOK_IFELSE) {
      emit (root);
      return;
   }
   for (size_t child = 0; child < root->children.size(); ++child) {
      
      if ((root->children.at(child)->symbol == TOK_WHILE) |
          (root->children.at(child)->symbol == TOK_IFELSE)|
          (root->children.at(child)->symbol == TOK_CALL)) {
         emit (root->children.at(child));
      }else
      postorder (root->children.at(child));
   }
   emit (root);
}
开发者ID:gravitystretch,项目名称:Simple_C_Compiler,代码行数:17,代码来源:emit.cpp


示例16: loopit

void
loopit(Reg *r, int32 nr)
{
	Reg *r1;
	int32 i, d, me;

	if(nr > maxnr) {
		rpo2r = mal(nr * sizeof(Reg*));
		idom = mal(nr * sizeof(int32));
		maxnr = nr;
	}

	d = postorder(r, rpo2r, 0);
	if(d > nr)
		fatal("too many reg nodes %d %d", d, nr);
	nr = d;
	for(i = 0; i < nr / 2; i++) {
		r1 = rpo2r[i];
		rpo2r[i] = rpo2r[nr - 1 - i];
		rpo2r[nr - 1 - i] = r1;
	}
	for(i = 0; i < nr; i++)
		rpo2r[i]->rpo = i;

	idom[0] = 0;
	for(i = 0; i < nr; i++) {
		r1 = rpo2r[i];
		me = r1->rpo;
		d = -1;
		// rpo2r[r->rpo] == r protects against considering dead code,
		// which has r->rpo == 0.
		if(r1->p1 != R && rpo2r[r1->p1->rpo] == r1->p1 && r1->p1->rpo < me)
			d = r1->p1->rpo;
		for(r1 = r1->p2; r1 != nil; r1 = r1->p2link)
			if(rpo2r[r1->rpo] == r1 && r1->rpo < me)
				d = rpolca(idom, d, r1->rpo);
		idom[i] = d;
	}

	for(i = 0; i < nr; i++) {
		r1 = rpo2r[i];
		r1->loop++;
		if(r1->p2 != R && loophead(idom, r1))
			loopmark(rpo2r, i, r1);
	}
}
开发者ID:jianfengye,项目名称:Go_source,代码行数:46,代码来源:reg.c


示例17: main

int main()
{

    //FILE*f=fopen("data.txt","r");
    //FILE*g=fopen("out.txt","w");
    Node*rad=constructie();
    printf("\npreordine\n");
    preorder(rad,0);
    printf("\ninordine\n");
    inorder(rad,0);
    printf("\npostorder\n");
    postorder(rad,0);
    //fclose(f);
    //fclose(g);

    return 0;
}
开发者ID:Alecs94,项目名称:DSA-lab,代码行数:17,代码来源:main.c


示例18: main

void main()
{
	node *root;
    insert(&root, 9);
    insert(&root, 4);
    insert(&root, 15);
    insert(&root, 6);
    insert(&root, 12);
    insert(&root, 17);
    insert(&root, 2);
	printf("PREORDER\n");
	preorder(root);
	printf("INORDER\n");
	inorder(root);
	printf("POSTORDER\n");
	postorder(root);
}
开发者ID:vineetdhanawat,项目名称:crack-the-interview,代码行数:17,代码来源:bstdfs.c


示例19: main

void main(void)
{
  int ch;
  char y;
  int data;
  struct node *temp;
  
  while(1)
  {
    printf("\n\n\n1: Insert\t2: Inorder Traversal\t3: Preorder Traversal\t4: Postorder Traversal\t5: Exit\nEnter you choice: ");
    scanf("%d",&ch);
    

    switch(ch)
    {
      case 1:
          printf("\nEnter data value: ");
          scanf("%d",&data);
          temp=new_node(data);
          if(root==NULL)
          {
            root=temp;
          }
          else
          insert(root,temp);

        break;

      case 2:
        inorder(root);
        break;

      case 3:
        preorder(root);
        break;

      case 4:
        postorder(root);
        break;

      case 5:
        exit(0);
      default: printf("\nInvalid Choice !");
    }
  }
}
开发者ID:gowtham-munukutla,项目名称:All-My-Codes,代码行数:46,代码来源:completebinarytree.c


示例20: main

void main(){
int no,ch;
printf("Enter root\n");
scanf("%d",&no);
root=make(no);
p=root;
while(1){
printf("\nEnter another no\n");
printf("\nEnter 0 to terminate\n");
scanf("%d",&no);
if(no==0)
break;
p=root;
q=root;
while(no!=p->data && q!=NULL){
p=q;
if(no< p->data)
q=p->left;
else
q=p->right;}
if(no < p->data){
printf("Left branch of %d is %d",p->data,no);
left(p,no);}
else{
right(p,no);
printf("Right branch of %d is %d",p->data,no);
}}
while(1)
{
printf("\n1:Inorder\n2:Preorder\n3:Postorder\n");
printf("Enter choice\n");
scanf("%d",&ch);
switch(ch)
{
case 1: inorder(root);
	break;
case 2: preorder(root);
	break;
case 3: postorder(root);
	break;
case 4: exit(0);
default : printf("Invalid choice\n");
	 break;

}}}
开发者ID:abhishek-annigeri,项目名称:abhishekannigeriblog,代码行数:45,代码来源:bst1.c



注:本文中的postorder函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ posy函数代码示例发布时间:2022-05-30
下一篇:
C++ postfl函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap