当前位置: 首页>>代码示例>>C++>>正文


C++ printTree函数代码示例

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


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


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