void PrintTree(struct Node *root) { // Perform Inorder Traversal of tree if(root==0) { return; } PrintTree(root->Left); printf(" %d ",root->Data); PrintTree(root->Right); }
// 测试二叉树:出叶子结点之外,左右的结点都有且只有一个左子结点 // 8 // 7 // 6 // 5 // 4 void Test2() { printf("=====Test2 starts:=====\n"); BinaryTreeNode* pNode8 = CreateBinaryTreeNode(8); BinaryTreeNode* pNode7 = CreateBinaryTreeNode(7); BinaryTreeNode* pNode6 = CreateBinaryTreeNode(6); BinaryTreeNode* pNode5 = CreateBinaryTreeNode(5); BinaryTreeNode* pNode4 = CreateBinaryTreeNode(4); ConnectTreeNodes(pNode8, pNode7, NULL); ConnectTreeNodes(pNode7, pNode6, NULL); ConnectTreeNodes(pNode6, pNode5, NULL); ConnectTreeNodes(pNode5, pNode4, NULL); PrintTree(pNode8); printf("=====Test2: MirrorRecursively=====\n"); MirrorRecursively(pNode8); PrintTree(pNode8); printf("=====Test2: MirrorIteratively=====\n"); MirrorIteratively(pNode8); PrintTree(pNode8); DestroyTree(pNode8); }
void SimulateCoalescentTree(int *method,int *sample,int *current,int *ancestral,int *time) { int max_nodes; Parameters P; FILE *treefile; GetRNGstate(); P.method = *method; P.n = *sample; P.current = *current; P.ancestral = *ancestral; P.time = *time; max_nodes = 2 * P.n - 1; // This is the maximum number of nodes in the complete genealogy list = (struct Node **) malloc (P.n * sizeof (struct Node *)); // These are the pointers to the remaining lineages tree = (struct Node *) malloc (max_nodes * sizeof(struct Node)); // This contains the full genealogy treefile = fopen(TREEFILE,"w"); if (P.method == 0) { BuildTreeGenerations(P); // Give a sample of genes from a (generation-by-generation) coalescent alogrithm with mutations PrintTree(&tree[nbr_nodes - 1],treefile); } else if (P.method == 1) { BuildTreeHudson(P); // Give a sample of genes from a (generation-by-generation) coalescent alogrithm with mutations PrintTree(&tree[2 * P.n - 2],treefile); } fclose(treefile); free(tree); // free the memory allocated for the structures 'tree', 'sample', and 'list' free(list); PutRNGstate(); }
// ====================测试代码==================== // 测试完全二叉树:除了叶子节点,其他节点都有两个子节点 // 8 // 6 10 // 5 7 9 11 void Test1() { printf("=====Test1 starts:=====\n"); BinaryTreeNode* pNode8 = CreateBinaryTreeNode(8); BinaryTreeNode* pNode6 = CreateBinaryTreeNode(6); BinaryTreeNode* pNode10 = CreateBinaryTreeNode(10); BinaryTreeNode* pNode5 = CreateBinaryTreeNode(5); BinaryTreeNode* pNode7 = CreateBinaryTreeNode(7); BinaryTreeNode* pNode9 = CreateBinaryTreeNode(9); BinaryTreeNode* pNode11 = CreateBinaryTreeNode(11); ConnectTreeNodes(pNode8, pNode6, pNode10); ConnectTreeNodes(pNode6, pNode5, pNode7); ConnectTreeNodes(pNode10, pNode9, pNode11); PrintTree(pNode8); printf("=====Test1: MirrorRecursively=====\n"); MirrorRecursively(pNode8); PrintTree(pNode8); printf("=====Test1: MirrorIteratively=====\n"); MirrorIteratively(pNode8); PrintTree(pNode8); DestroyTree(pNode8); }
void MSTree::PrintTree(MSTreeNode* rt) { if (rt==NULL) return; rt->PrintNode(); // call PrintNode, print out the NormD PrintTree(rt->LeftChild); PrintTree(rt->RightChild); }
int main(int argc, char *argv[]) { BiTree *root1, *root2; BiTree *tmp; char temp[20]; int flag = 0; printf("请输入第一棵书\n"); root1 = CreatTree_char(root1); printf("创建成功\n"); PrintTree(root1, 1); changes(root1); printf("\n\n\n"); PrintTree (root1, 1); // Print(root1, 1); //CountParent(root1, &flag); // printf("个数为%d\n", flag); return EXIT_SUCCESS; }
void PrintTree(BNode* tree, unsigned int printLevel = 0) { for (unsigned int i = 0; i < printLevel; i++) { printf(" "); } if (printLevel > 0) { printf("+"); } if (!tree) { printf("(null)\n"); return; } std::string output = ""; output += "("; output += std::to_string(printLevel); output += ")"; output += "Name: " + tree->name; output += (tree->sibling ? " : Sibling: " + tree->sibling->name : ""); output += "\n"; printf("%s", output.c_str()); unsigned int nextLevel = printLevel + 1; PrintTree(tree->right, nextLevel); PrintTree(tree->left, nextLevel); }
void PrintTree(const BinNode *p){ if ( p != NULL ){ PrintTree(p->left); printf("%s\n",p->name); PrintTree(p->right); } }
void PrintTree(BinNode *p) { if (p != NULL){ PrintTree(p->left); PrintData(p->data); PrintTree(p->right); } }
// Skriv ut trädet void PrintTree(objekt *x) { if(x!=NULL) { PrintTree(x->left); printf("%d ",x->nyckel); PrintTree(x->right); } }
//for testing void Encoding::PrintTree(node* tree){ cout << tree->letter << " at weight " << tree->weight << endl; if (tree->leftChild != NULL){ PrintTree(tree->leftChild); } if (tree->rightChild != NULL){ PrintTree(tree->rightChild); } }
void PrintTree(BinaryTreeNode* pRoot) { if (pRoot != NULL) { PrintTreeNode(pRoot); if(pRoot->m_pLeft != NULL) PrintTree(pRoot->m_pLeft); if(pRoot->m_pRight != NULL) PrintTree(pRoot->m_pRight); } }
void PrintTree(AvlTree T) { if (T) { cout << T->Element << " "; PrintTree(T->Left); PrintTree(T->Right); } }
int main(int argc, char *argv[]) { struct node* root = NULL; struct nodeNumber* rootNumber = NULL; time_t inicio, final; time(&inicio); if (argc != 3) { fprintf(stderr, "Error: Problem with the number of parameters\n"); fprintf(stderr, " on the command line\n"); fprintf(stderr, "Use:\n"); fprintf(stderr, " dicttool option 'file_in' > 'file_out'\n"); fprintf(stderr, "option:\n"); fprintf(stderr, " 1 to seek words only\n"); fprintf(stderr, " 2 to check urls\n"); fprintf(stderr, " 3 to find numberss\n"); fprintf(stderr, " 4 to seek only words and counting\n"); fprintf(stderr, " 5 to check urls and counting\n"); fprintf(stderr, " 6 to check numbers and counting\n"); exit(8); }; int option = atoi(argv[1]); switch (option) { case 1: PrintTree(ScanWords(argv[2])); break; case 2: PrintTree(ScanURL(argv[2])); break; case 3: PrintNumbers(ScanNumbers(argv[2])); break; case 4: PrintTreeCount(ScanWords(argv[2])); break; case 5: PrintTreeCount(ScanURL(argv[2])); break; case 6: PrintNumbersCount(ScanNumbers(argv[2])); break; default: { fprintf(stderr, "option:\n"); fprintf(stderr, " 1 to seek words only\n"); fprintf(stderr, " 2 to check urls\n"); fprintf(stderr, " 3 to find numberss\n"); fprintf(stderr, " 4 to seek only words and counting\n"); fprintf(stderr, " 5 to check urls and counting\n"); fprintf(stderr, " 6 to check numbers and counting\n"); } } time(&final); double diff = difftime(final, inicio); printf("It took %.2lf seconds to run\n", diff); return (0); }
void PrintTree (BinTree *T) //递归调用 前序遍历 { if (T != NULL ) { printf("%d \t" , T->data ); PrintTree(T->Left); // printf("%d \t" , T->data ); //中序遍历 PrintTree(T->Right); } }
void UndoEngine::PrintTrees() { std::stringstream cstr; cstr << "OldTree: " << endl; PrintTree(m_oldtree.m_tree,cstr,0); cstr << "NewTree: " << endl; PrintTree(m_tree.m_tree,cstr,0); debugprint(cstr.str()); cstr.clear(); }
void PrintTree(TreeNode* tree, std::ofstream& outFile) // Prints info member of items in tree in sorted order on outFile. { if (tree != NULL) { PrintTree(tree->left, outFile); // Print left subtree. outFile << tree->info; PrintTree(tree->right, outFile); // Print right subtree. } }
void PrintTree( SplayTree T ) { if( T != NullNode ) { PrintTree( T->Left ); printf( "%d ", T->Element ); PrintTree( T->Right ); } }
void PrintTree(BitTree Boot,int nLayer) //按竖向树状打印的二叉树 // { int i; if(Boot==NULL) return; PrintTree(Boot->RChild,nLayer+1); for(i=0;i<nLayer;i++) printf(" "); printf("%c\n",Boot->data); PrintTree(Boot->LChild,nLayer+1); }
static void PrintTree (DirEntry_s *direntry, int indent) { if (!direntry) return; if (Option.print) { Indent(indent); printf("%s %s\n", direntry->type == T_DIR ? "D" : "F", direntry->name); } PrintTree(direntry->child, indent + 1); PrintTree(direntry->sibling, indent); }
// 测试用的输出数组中的每个二项树 void PrintTree(BinTree T) { if(T == NULL) { return; } printf("%d ", T->Element); PrintTree(T->NextSibling); PrintTree(T->LeftChild); }
SearchTree PrintTree ( SearchTree T ) { static int i = 1 ; if ( T != NULL ) { PrintTree ( T->Left ) ; printf ( "The Element is: %d\n", T->Element ) ; PrintTree ( T->Right ) ; } else return NULL ; }
void PrintTree(const NODE *pNode) { if (pNode != NULL) { PrintTree(pNode->left); /* traverse left */ printf("%4d %s\n", (int)pNode->count, pNode->strng); PrintTree(pNode->right); /* traverse right */ } }
void PrintTree(struct node* nodes) /*function to print the tree*/ { if(nodes==NULL) return; PrintTree(nodes->left); printf("\t%d(count %d)\n",nodes->key,nodes->num); printf("\t|\n\tV\n"); PrintTree(nodes->right); }
//------------------------------------------------------------------------------ //обход дерева int PrintTree(Node *p, int level) { if (p) { PrintTree(p->left, level+1); //вывод левого поддерева for (int i=0;i<level;i++) printf(" "); printf("%c\n", p->d); //вывод корня поддерева PrintTree(p->right, level+1); //вывод правого поддерева return 0; } }
void PrintTree(TreeNode *root) { if (root != NULL) { LinkNode *p = root->lines; PrintTree(root->left); printf("%15s: ", root->word); while (p = p->next) { printf("%4d ", p->line_num); } putchar('\n'); PrintTree(root->right); } }
//------------------------------------------------------------------------------ std::string PrintTree( node * root ){ if( root == nullptr ){ return "."; } std::string msg = "{ "; msg += PrintTree( root->left ); msg += " " + std::to_string( root->data ) + " "; msg += PrintTree( root->right ); msg += " }"; return msg; }
/*打印树,先答应左子树再打印右子树*/ void PrintTree(SearchTree T) { if(T == NULL) { perror("wrong tree"); exit(1); } if(T->lchild != NULL) PrintTree(T->lchild); printf("%d\n",T->Element); if(T->rchild !=NULL) PrintTree(T->rchild); }
char *PrintTree(Node *t) { char *str; str = calloc(STRSIZE, sizeof(char)); assert(str != NULL); if(t == NULL) { strcpy(str, "*"); return str; } sprintf(str, "%d(%s)(%s)", t->num, PrintTree(t->left), PrintTree(t->right)); return str; }
/*打印树,depth为根节点的初始化深度*/ void PrintTree(SearchTree T, int depth) { if(T == NULL) { perror("wrong tree"); exit(1); } if(T->lchild != NULL) PrintTree(T->lchild, depth+1); PrintDepth(T->Element, depth); if(T->rchild !=NULL) PrintTree(T->rchild, depth+1); }