Exemple #1
0
bitree_t *CreateBitree(int i, bt_data_t data[], int n)
{
	bitree_t *root;
	int j;
	
	root = (bitree_t *)malloc(sizeof(bitree_t));
	root->data = data[i];
	
	j = 2 * i;
	if (j <= n && data[j] != NULL_DATA) {
		/* must have left child */
		root->lchild = CreateBitree(j, data, n);
	} else {
		/* no left child */
		root->lchild = NULL;
	}
	
	j = 2 * i + 1;
	if (j <= n && data[j] != NULL_DATA) {
		/* must have right child */
		root->rchild = CreateBitree(j, data, n);
	} else {
		/* no right child */
		root->rchild = NULL;
	}

	return root;
}
Exemple #2
0
CreateBitree(BiTree *T){
    char c;
    scanf("%c",&c);
    if(c == ' ')
        *T = NULL;
    else{
        *T = (BiTNode * )malloc(sizeof(BiTNode));
        (*T)->data = c;
        CreateBitree(&((*T)->lchild));
        CreateBitree(&((*T)->rchild));
    }
}
Exemple #3
0
Status CreateBitree(BiTree * T) {
	char ch;

	scanf("%c", &ch);
	if (ch == ' ') *T = NULL;
	else {
		if (!(*T = (BiTNode *)malloc(sizeof(BiTNode)))) exit(OVERFLOW);
		(*T)->data = ch;
		
		CreateBitree(&(*T)->lchild);
		CreateBitree(&(*T)->rchild);
	}

	return OK;
}
Exemple #4
0
int main(){
    int level=1;
    BiTree T = NULL;
    CreateBitree(&T);
    PosOrderTraverse(T,level);
    getche();
}
Exemple #5
0
int main(int argc, char const *argv[])
{
	BiTree test = NULL;

	CreateBitree(&test);
	PreOrderTraverse(test, PrintElement);

	return 0;
}