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

C++ printTree函数代码示例

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

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



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

示例1: printTree

/* procedure printTree prints a syntax tree to the
 * listing file using indentation to indicate subtrees
 */
void printTree( TreeNode * tree )
{ int i;
  INDENT;
  while (tree != NULL) {
    printSpaces();
    if (tree->nodekind==StmtK){
      switch (tree->kind.stmt) {
        case IfK:
          fprintf(listing,"If\n");
          break;
        case RepeatK:
          fprintf(listing,"Repeat\n");
          break;
        case ForK:
          fprintf(listing,"For\n");
          break;
        case AssignK:
          fprintf(listing,"Assign to: %s\n",tree->attr.name);
          break;
        case ReadK:
          fprintf(listing,"Read: %s\n",tree->attr.name);
          break;
        case WriteK:
          fprintf(listing,"Write\n");
          break;
        default:
          fprintf(listing,"Unknown ExpNode kind\n");
          break;
      }
    }
    else if (tree->nodekind==ExpK){
      switch (tree->kind.exp) {
        case OpK:
          fprintf(listing,"Op: ");
          printToken(tree->attr.op,"\0");
          break;
        case ConstK:
          fprintf(listing,"Const: %d\n",tree->attr.val);
          break;
        case IdK:
          fprintf(listing,"Id: %s\n",tree->attr.name);
          break;
        default:
          fprintf(listing,"Unknown ExpNode kind\n");
          break;
      }
    }
    else fprintf(listing,"Unknown node kind\n");
    for (i=0;i<MAXCHILDREN;i++)
         printTree(tree->child[i]);
    tree = tree->sibling;
  }
  UNINDENT;
}
开发者ID:SamirSouzaSys,项目名称:UFMA_Compiladores_Tiny_20152,代码行数:57,代码来源:util.c


示例2: search

int search(Board b, int maxDepth, int m, int n)
{
	searchNode* head = new searchNode(b);
	nodeCounter = 0;
	std::cout << "\n** R.Reti Endgame Board **\n";
	head->printBoardImage();
	int topHeurisic = _search(head,maxDepth,0,UNSET);
	printTree(head,m,n);
	printBest(head);
	return topHeurisic;
}
开发者ID:robfitzgerald,项目名称:csci5582-chess-endgame,代码行数:11,代码来源:search.cpp


示例3: Test

void Test(char* testName, BinaryTreeNode* pRootOfTree)
{
    if(testName != NULL)
        printf("%s begins:\n", testName);

    printTree(pRootOfTree);

    BinaryTreeNode* pHeadOfList = convertBSTToList(pRootOfTree);

    PrintDoubleLinkedList(pHeadOfList);
}
开发者ID:newtonker,项目名称:GetOfferPractise,代码行数:11,代码来源:ConvertBSTToList.cpp


示例4: printTree

// Prints the tree to the screen in a readable fashion. It should look just like
// Racket code; use parentheses to indicate subtrees.
void printTree(Value *tree) {    
    Value *list_pointer = tree;
    
    // handle printing dependent on what type the item in the list is.
    while ((*list_pointer).type == CONS_TYPE) {
        Value *car_of_list_pointer = car(list_pointer);
        //printf("%u", (*car_of_list_pointer).type);
        
        switch ((*car_of_list_pointer).type) {
            case STR_TYPE:
                printf("%s", (*car_of_list_pointer).s);
                break;
            case DOUBLE_TYPE:
                printf("%f", (*car_of_list_pointer).d);
                break;
            case INT_TYPE:
                printf("%i", (*car_of_list_pointer).i);
                break;
            case CONS_TYPE:
                printf("(");
                printTree(car_of_list_pointer);
                printf(")");
                break;
            case NULL_TYPE:
                printf("()");
                break;
            case OPEN_TYPE:
                // do nothing.
                break;
            case CLOSE_TYPE:
                // do nothing.
                break;
            case BOOL_TYPE:
                if ((*car_of_list_pointer).i == 1) {
                    printf("#t");
                } else {
                    printf("#f");
                }
                break;
            case SYMBOL_TYPE:
                printf("%s", (*car_of_list_pointer).s);
                break;
            case PTR_TYPE:
                break;
        }
        
        if ((*((*list_pointer).c).cdr).type != NULL_TYPE) {
            printf(" ");
        }
        
        
        list_pointer = ((*list_pointer).c).cdr;
    }
}
开发者ID:stensaethf,项目名称:Racket-Interpreter,代码行数:56,代码来源:parser.c


示例5: main

int main(int argc, char *argv[])
{	
  struct Tree *gameTree	= malloc (sizeof(struct Tree));
	gameTree->root = parseFile();
	
	if (DEBUG) printTree(gameTree);
	play (gameTree);
	writeFile(gameTree);
  clearTree(gameTree);
	return 0;
}
开发者ID:Maker23,项目名称:osu_classes,代码行数:11,代码来源:main.c


示例6: main

int main( int argc, char * argv[] )
{ TreeNode * syntaxTree;
  char pgm[120]; /* source code file name */
  if (argc != 2)
    { fprintf(stderr,"usage: %s <filename>\n",argv[0]);
      exit(1);
    }
  strcpy(pgm,argv[1]) ;
  if (strchr (pgm, '.') == NULL)
     strcat(pgm,".cm");
  source = fopen(pgm,"r");
  if (source==NULL)
  { fprintf(stderr,"File %s not found\n",pgm);
    exit(1);
  }
  listing = stdout; /* send listing to screen */
  fprintf(listing,"\nTINY COMPILATION: %s\n",pgm);
#if NO_PARSE
  while (getToken()!=ENDFILE);
#else
  syntaxTree = parse();
  if (TraceParse) {
    fprintf(listing,"\nSyntax tree:\n");
    printTree(syntaxTree);
  }
#if !NO_ANALYZE
  if (! Error)
  { if (TraceAnalyze) fprintf(listing,"\nBuilding Symbol Table...\n");
    buildSymtab(syntaxTree);
    if (TraceAnalyze) fprintf(listing,"\nChecking Types...\n");
    typeCheck(syntaxTree);
    if (TraceAnalyze) fprintf(listing,"\nType Checking Finished\n");
  }
#if !NO_CODE
  if (! Error)
  { char * codefile;
    int fnlen = strcspn(pgm,".");
    codefile = (char *) calloc(fnlen+4, sizeof(char));
    strncpy(codefile,pgm,fnlen);
    strcat(codefile,".tm");
    code = fopen(codefile,"w");
    if (code == NULL)
    { printf("Unable to open %s\n",codefile);
      exit(1);
    }
    codeGen(syntaxTree,codefile);
    fclose(code);
  }
#endif
#endif
#endif
  fclose(source);
  return 0;
}
开发者ID:isairz,项目名称:cminus,代码行数:54,代码来源:main.c


示例7: printTree

void printTree(huffmanTree* completed)
{
	if(isLeaf(completed))
	{
		printdepthOfNode(completed);
		return;
	}

	if(completed->left!=NULL)
	{
		printTree(completed->left);
	}

	if(completed->right!=NULL)
	{
		printTree(completed->right);
	}

	return;
}
开发者ID:chrstphrdlz,项目名称:HuffmanComressor,代码行数:20,代码来源:Huffman.cpp


示例8: main

int main(int argc, const char * argv[]) {
    node<int> *root = new node<int>;
    root->data = 0;
    node<int> *child1 = new node<int>;
    child1->data = 1;
    node<int> *child5 = new node<int>;
    child5->data = 5;
    node<int> *child3 = new node<int>;
    child3->data = 3;
    node<int> *child4 = new node<int>;
    child4->data = 4;
    node<int> *child2 = new node<int>;
    child2->data = 2;
    node<int> *child12 = new node<int>;
    child12->data = 12;
    node<int> *child6 = new node<int>;
    child6->data = 6;
    node<int> *child9 = new node<int>;
    child9->data = 9;
    node<int> *child8 = new node<int>;
    child8->data = 8;
    node<int> *child7 = new node<int>;
    child7->data = 7;

    child6->left = child4;
    child4->parent = child6;
    child6->right = child9;
    child9->parent = child6;
    child4->left = child3;
    child3->parent = child4;
    child4->right = child5;
    child5->parent = child4;
    child3->left = child1;
    child1->parent = child3;
    child9->left = child7;
    child7->parent = child9;


    printTree(child6);

    node<int> *ancestor = findCommonAncestor(child1, child9);
    if ( ancestor )
        std::cout << "\nfound common ancestor = " << ancestor->data << "\n";
    else
        std::cout << "\nno common ancestor found\n";

    ancestor = findCommonAncestor(child9, child1);
    if ( ancestor )
        std::cout << "\nsearching the other way = " << ancestor->data << "\n";
    else
        std::cout << "\nno common ancestor found\n";

    return 0;
}
开发者ID:GalitMiller,项目名称:sandbox,代码行数:54,代码来源:main.cpp


示例9: printTreeList

void printTreeList(ListObject * trees, int indent)
{

    if (trees == 0) {

        return;

    }

    printTree(trees->value, indent);

    while (trees->next != 0) {

        trees = trees->next;

        printTree(trees->value, indent);

    }

}
开发者ID:riolet,项目名称:rix,代码行数:20,代码来源:ObjectTree.c


示例10: printf

void XMLParser::printTree(xmlNodePtr start, int depth) const
{
	for(int i=0;i<depth;i++)
		printf("%d",(i+1)%10);
	printf("\"%s\":\"%s\"\n",(start->name),this->getNodeContent(start).c_str());
	xmlNodePtr i = this->getChild(start);
	for(;i;i= this->getNext(i))
	{
		printTree(i,depth+1);
	}
}
开发者ID:knightL,项目名称:StandingsBuilder,代码行数:11,代码来源:XMLParser.cpp


示例11: bipartGraphPrint

void bipartGraphPrint(bpGraph_t *pGraph)
{
	printf("Vertices:\n");
	printf("Part 1:\n");
    printTree(pGraph->vpVertsP1);
    printf("\n");

	printf("Part 2:\n");
    printTree(pGraph->vpVertsP2);
	printf("\n");

	printf("Edges:\n");
	/* partite 1 to partite 2 edges. */
	printf("Part 1 to 2:\n");
	printLList(pGraph->vpVertsP1);
	
	/* partite 2 to partite 1 edges. */
	printf("Part 2 to 1:\n");
	printLList(pGraph->vpVertsP2);
} /* end of bipartGraphPrint() */
开发者ID:j1nhu,项目名称:Bipartite-Graph,代码行数:20,代码来源:bpGraphAdjList_BL.c


示例12: main

int main(void) {
	BST<int> myTree;
	myTree.insert(3);

	for (int32_t k = 20; k < 100; k += 1) {
		myTree.insert(k);
	}

	printTree(myTree);

}
开发者ID:tabchas,项目名称:ee312,代码行数:11,代码来源:main.cpp


示例13: printTree

void printTree (tree t) {
	if (t == NULL) return;
	for (; t != NULL; t = t->next) {
		printf ("%*s%s", indent, "", tokName[t->kind]);
		switch (t->kind) {
			case Ident:
				printf ("		%s (%d)\n", id_name(t->value), t->value);
				break;
			case IntConst:
				printf ("		%d\n", t->value);
				break;
			default:
				printf ("\n");
				indent += 2;
				printTree (t->first);
				printTree (t->second);
				printTree (t->third);
				indent -= 2;
		} // end switch
	} // end for loop
} // end printTree()
开发者ID:bdlindsay,项目名称:cs4280Project,代码行数:21,代码来源:tree.c


示例14: imprime_hash

void imprime_hash(Thash *hash) {

	int i;
    unsigned int cont=0;

	for(i = 0; i < TAM_HASH; i++) {

    	printTree(hash[i].raiz,&cont);
	}
	printf("n_uniq %u\n",cont);
	printf("sum_uniq %llu\n",numdist);
}
开发者ID:anotacoesufpr,项目名称:anotacoes-ufpr,代码行数:12,代码来源:hash.c


示例15: printTree

//Prints the bit representation of the given leaf
void printTree(TREE *fir)
{
    //postorder print of the path to the given leaf
    if(getParent(fir)!=NULL)
    {
        printTree(getParent(fir));
        if(getLeft(getParent(fir))==fir)
            printf("0");
        else
            printf("1");
    }
}
开发者ID:patback66,项目名称:COEN12,代码行数:13,代码来源:huffman.c


示例16: main

int main()
{
    char *values;
    int size;
    readExpression(&values, &size);

    initStack(size);
    createTree(values, size);
    printTree("tree.txt");

    return EXIT_SUCCESS;
}
开发者ID:KovaxG,项目名称:aut-eng-2014,代码行数:12,代码来源:main.c


示例17: printTree

/*==============================================
Prints the Tree
==============================================*/
void printTree(TreeBranch * cur, int indent)
{
	int i = 0;
	while(i < indent)								
	{
		printf(" ");
		i++;
	}
	if(cur->type != NULL)
		printf("%s ", cur->type);
	if(cur->subtype != NULL)
		printf("%s ", cur->subtype);
	if(cur->attribute != NULL)
		printf("[%s]\n", cur->attribute);
	else if(cur->flag == 1)
		printf("%i\n", cur->num);
	else printf("\n");

	if(cur->child1 != NULL)
    {
	    printf("child1:  ");
		printTree(cur->child1, (indent+2));
	}
	if(cur->child2 != NULL)
	{
	    printf("child2:  ");
		printTree(cur->child2, (indent+2));
	}
	if(cur->child3 != NULL)
	{
	    printf("child3:  ");
		printTree(cur->child3, (indent+2));
    }
    if(cur->sibling != NULL)
	{
	    printf("sibling: ");
		printTree(cur->sibling, indent);
	}
	return;
}
开发者ID:OlesenA77,项目名称:Compiler,代码行数:43,代码来源:tree.c


示例18: switch

void BinarySearchTree<T>::printTree(Node<T>* subTree, Order order) const
{
    if (subTree == nullptr) return;

    switch (order)
    {
    case Order::PRE_ORDER:
            std::cout<<subTree->getValue()<<" ";

            printTree(subTree->getLeft(), order);

            printTree(subTree->getRight(),order);

            break;

     case 1:
            printTree(subTree->getLeft(), order);

            std::cout<<subTree->getValue()<<" ";

            printTree(subTree->getRight(),order);

            break;

     case 2:
            printTree(subTree->getLeft(), order);

            printTree(subTree->getRight(),order);

            std::cout<<subTree->getValue()<<" ";

            break;
     }

}
开发者ID:LDercher,项目名称:Programming-2,代码行数:35,代码来源:binarysearchtree.hpp


示例19: main

int main(int argc, char **argv)
{
	//Checking error
	if (argc < 2)
	{
		printf("usage: %s <input_filename>\n", argv[0]);
		return 0;
	}
	//Open file
	FILE *in = fopen(argv[1], "r");
	if (in == NULL) return 0;
	//Declaration of variable
	int i, size,level;
	//Scanning size from file
	fscanf(in, "%d", &size);
	//allocating memory for array
	int *array = malloc(size * sizeof(int));
	//Scanning number from the file
	for (i=0; i<size; i++)
		fscanf(in, "%d", &array[i]);
	//Declaring a node
	bst *root =NULL;
	//Creating BST
	root=createBST(array,size);
	//print in-order,pre-order,post-order tree traversal
	printf("Creating Binary Search Tree...\n");
	printf("In-order traversal: "); 
	printInorder(root); 
	printf("\n");
	printf("Pre-order traversal: ");
	printPreorder(root);
	printf("\n");
	printf("Post-order traversal: ");
	printPostorder(root);
	printf("\n");
	//Sort arrat
	sort(array,size);
	//Creatin binary tree with minimum level
	root=createMinBST(array,0,size-1);
	//printing BST
	printf("Minimum Height BST\n");
	printTree(root);
	//Bonus
	printf("Bonus.Please enter level of the tree:");
	scanf("%d",&level);
	if(level>height(root))
	printf("\nThe maximum height of this tree is %d",height(root));
	else
	printGivenLevel(root,level);

 return 0;
}
开发者ID:Lagaunne-Timotius,项目名称:classes,代码行数:52,代码来源:lab9.c


示例20: testmain

int testmain()
{

    Object *root = CreateObject("Undefined", "Undefined", 0, CodeBlock, "int");
    Object *basetype = CreateObject("BaseType", "BaseType", 0, Type, 0);
    Object *rect = CreateObject("Rectangle", "BaseType_Rectangle", basetype, Type, 0);
    Object *rectConst =
        CreateObject("Rectangle", "Rectangle_Rectangle_Rectangle_int_int", 0,
                     Constructor, "Rectangle");
    Object *subexpr = CreateObject(0, 0, 0, Expression, "float");
    addCode(subexpr, "3.14159");
    addParam(rectConst, "int");
    addParam(rectConst, "int");
    addSymbol(rectConst, CreateObject("width", "width", 0, Variable, "int"));
    addSymbol(rectConst, CreateObject("height", "height", 0, Variable, "int"));
    addSymbol(rectConst, CreateObject("self", "self", 0, Variable, "Rectangle*"));
    addCode(rectConst,
            "Rectangle * Rectangle_Rectangle_Rectangle_int_int(int width, int height) {");
    addCode(rectConst, "    Rectangle * self = (Rectangle*)malloc(sizeof(Rectangle));");
    addCode(rectConst, "    self->w = width;");
    addCode(rectConst, "    self->h = height;");
    addCode(rectConst, "    return self;");

    addCode(rectConst, "}");

    addSymbol(rect, CreateObject("w", "w", 0, Variable, "int"));

    addSymbol(rect, CreateObject("h", "h", 0, Variable, "int"));

    addSymbol(rect, rectConst);

    addCode(rect, "typedef struct {");

    addCode(rect, "    BaseType parent;");

    addCode(rect, "    int w;");

    addCode(rect, "    int h;");

    addCode(rect, "} Rectangle;");

    addSymbol(root, basetype);

    addSymbol(root, rect);

    addSymbol(root, subexpr);

    printTree(root, 0);

    return 0;

}
开发者ID:riolet,项目名称:rix,代码行数:52,代码来源:ObjectTree.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ printValue函数代码示例发布时间:2022-05-30
下一篇:
C++ printToConsole函数代码示例发布时间: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