标签:val span main one col bit dep int creat
struct Bitnode { struct Bitnode *left,*right; int val; }; typedef struct Bitnode Bitnode; Bitnode *CreatBitree_level() { Bitnode *Q[100]; int front=1,rear=0,n; Bitnode *root=NULL,*s; while(scanf("%d",&n),n!=-1) { if(n==0) s=NULL; else { s=(Bitnode*)malloc(sizeof(Bitnode)); s->val=n; s->left=NULL; s->right=NULL; } Q[++rear]=s; if(rear==1) root=s; else { if(s&&Q[front]) { if(rear%2==0) Q[front]->left=s; else Q[front]->right=s; } if(rear%2==1) front++; } } return root; } int depth(Bitnode *root) { if(root==NULL) return 0; int x,y; x=depth(root->left); y=depth(root->right); return x>y?x+1:y+1; }
#include <bits/stdc++.h> using namespace std; int a[105],t=0; struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; }; TreeNode* build(TreeNode * &root,int g) { if(g>t||a[g]==0) { root=NULL; return root; } root=(TreeNode*)malloc(sizeof(TreeNode)); root->val=a[g]; build(root->left,2*g); build(root->right,2*g+1); return root; } int main() { int n,m,i,j,k; while(cin>>k,k!=-1) a[++t]=k; TreeNode *root; root=build(root,1); cout<<k<<endl; }
标签:val span main one col bit dep int creat
原文地址:https://www.cnblogs.com/ww123/p/9569107.html